Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Bear 40 posts 129 karma points
    Oct 04, 2012 @ 12:19
    Bear
    0

    Conversion of XML back into CMSNode or Content

    Given that I have a node in XML form, such as;

    <node id="1049" version="808a2aad-3666-49ce-8e8f-0b53a9c1800f" parentID="1048" level="2" writerID="0" nodeType="1046" template="0" sortOrder="0" createDate="2008-06-01T23:12:54" updateDate="2012-10-02T15:31:38" nodeName="My Node" urlName="mynode" writerName="Administrator" nodeTypeAlias="SomeType" path="-1,1048,1049">
    <data alias="navigation-breadcrumbs">1</data>
    <data alias="on-public-menu">1</data>
    <data alias="on-suppliers-menu">0</data>
    <data alias="headline-breadcrumbs">1</data>
    <data alias="on-members-menu">0</data>
    <data alias="menu-option-hide">0</data>
    <data alias="page-name"/>
    <data alias="body-copy">
    <![CDATA[
    <p><img src="/media/174164/sign_200x133.jpg" width="200" height="133" alt="Sign" style="float: right;"/>Consider it a divorce. What killed the dinosaurs? The ice age. Give you a lift? Hey, I'm a police officer. This is an arrest. I'm a cop you idiot! I'm detective John Kimble. This man is under arrest. No sequel for you. Only pain. When the governor get's here, call me. Just bodies. Take it BACK. Give you a lift? Excuse me. Don't disturb my friend. He's dead tired. Take your toy back to the carpet. Get to the choppa. I've seen you before. You're the asshole on TV. Como esta. I'm the party pooper. Hey, I'm a police officer. This is an arrest. I'm a cop you idiot! I'm detective John Kimble. This man is under arrest. I have my orders. You should not drink and bake. You are not sending ME to the coola. Put the cookie down. Now!</p>
    
     <p><a href="/{localLink:1067}" title="Collaboration">Read
     more<br />
     </a></p>
    ]]>
    </data>
    <data alias="menu-option-lesser">0</data>
    </node>                       

    What do I call to convert this back to a CMSNode or Content Node? Something like...

    var cmsNode = new CMSNode(theXmlAbove);
  • Matt Brailsford 4124 posts 22215 karma points MVP 9x c-trib
    Oct 04, 2012 @ 12:32
    Matt Brailsford
    0

    I don't think you can go from Xml to CMSNode. You can go the other way by calling cmsNode.ToXml(...) but there doesn't look to be an alternative method for the other way.

    Your problem aswell is the CMSNode is pretty much read only, so it doesn't look like you can create a CMSNode and populate it with the values.

    What is it you need this for? maybe there is another way to do it.

    Matt

  • Matt Brailsford 4124 posts 22215 karma points MVP 9x c-trib
    Oct 04, 2012 @ 12:36
    Matt Brailsford
    0

    Ok, best I could suggest is actually create a Document entity and populate that manually with the values from the XML, so maybe something like:

    var node = new Document(id, false); //False tells it not to auto setup
    //TODO: Populate node values
    var cmsNode = (CMSNode)node;

    This is untested though

    Matt 

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Oct 04, 2012 @ 12:58
    Jeroen Breuer
    0

    Hmm you can convert it to umbraco.NodeFactory.Node if you want too. Example:

    string xml = ""; //Put the above xml in here

    XmlDocument doc = new XmlDocument();
    doc.LoadXml(xml);
    umbraco.NodeFactory.Node node = new umbraco.NodeFactory.Node(doc.DocumentElement);

    This example might also help: http://our.umbraco.org/wiki/reference/code-snippets/add-fake-property-to-a-content-node.

    Jeroen

  • Bear 40 posts 129 karma points
    Oct 04, 2012 @ 14:32
    Bear
    0

    Hey thanks for both of these replies!

    @Matt - I was going down that route of creating a document e.g.

    var newDoc = Document.MakeNew(name, docType, new User(0), parentId); 

    @Jeroen - I'll try call with the NodeFactory, I think that's actually what I'm after!

Please Sign in or register to post replies

Write your reply to:

Draft