Copied to clipboard

Flag this post as spam?

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


  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Sep 07, 2012 @ 13:12
    Bo Damgaard Mortensen
    0

    Grasping parsing of DynamicXml

    Hi all,

    I'm trying to get my head around parsing XML (and DynamicXml for that matter) in Razor.

    I have a custom datatype which stores parsable XML in the Umbraco XML cache and the structure is as follows:

    <ArrayOfMyObject>
         <MyObject>
             <ChildNode1>Text</ChildNode1>
       <ChildNode2>Text</ChildNode2>
         </MyObject>
    </ArrayOfMyObject>

    In Razor, when I try to access the property, let's just call it "MyProperty", like this:

    var xml = Model.MyProperty

    It gives me an error telling me that MyProperty doesn't exist. When I just output the property like this:

    @Model.GetPropertyValue("MyProperty")

    It outputs the XML structure.

    When I do this:

    var xml = @Library.ToDynamicXml(artist.GetPropertyValue("MyProperty"));

    It outputs:

    MacroEngines.DynamicXml

    So it seems that my datatypes XML is not stored as DynamicXml? Or? Also, when I try to loop through the DynamicXml after using the library method like this:

    foreach(var item in xml.ArrayOfMyObject.MyObject)
    {
    
    }

    It tells me that ArrayOfMyObject can't be found.

    So, am I forced to parse through my XML the standard way in C# by using XDocument and XElement?

    Any clarification on this is greatly appreciated! :-)

    Thanks in advance.

    All the best,

    Bo

  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Sep 09, 2012 @ 18:35
    Bo Damgaard Mortensen
    1

    Turns out the correct way of parsing the XML was this:

    var xml = @Library.ToDynamicXml(artist.GetPropertyValue("MyProperty");
    foreach(var value in xml) {
    @value.ChildNode1

     

  • Damian Chambers 23 posts 87 karma points
    Feb 05, 2015 @ 03:04
    Damian Chambers
    0

    How do I add values to existing xml file in Umbraco?

  • Liam 22 posts 158 karma points
    Oct 20, 2015 @ 16:07
    Liam
    0

    Bookmarked

Please Sign in or register to post replies

Write your reply to:

Draft