Copied to clipboard

Flag this post as spam?

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


  • Neo Liu 1 post 71 karma points
    Sep 02, 2019 @ 02:40
    Neo Liu
    0

    Umbraco v8: Load and Convert XML into dynamic object with inner text and attributes

    I am currently upgrading my Umbraco v7 application into Umbraco v8. I need to load XML file by its URL and convert it into a dynamic object.

    XML example:

    <targetData>
       <Properties>
          <Property attrOne="hello" attrTwo="World">Property 1</Property>
          <Property attrOne="Umbraco" attrTwo="">Property 2</Property>
       </Properties>
    </targetData>
    

    In Umbraco v7, I can do it in this way:

    using Umbraco.Core.Dynamics;
    
    dynamic xmlDynObj= new DynamicXml(Umbraco.library.GetXmlDocumentByUrl(xmlURL));
    
    foreach (dynamic eachProp in xmlDynObj.Properties.Property){
        //do something with eachProp's InnerText and Attributes
    }
    

    Now in Umbraco v8, it seems this method is no longer existing (or I didn't get it right, please let me know if it still exists). I am wondering if there is any replacement/alternative for GetXmlDocumentByUrl and DynamicXml can do the same work for me?

    Thanks.

Please Sign in or register to post replies

Write your reply to:

Draft