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 712 posts 1189 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 712 posts 1189 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 20 posts 84 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

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies