Copied to clipboard

Flag this post as spam?

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


  • Euge 23 posts 130 karma points
    Sep 25, 2013 @ 12:51
    Euge
    0

    Read in XML file and transform to HTML with Razor

    Hi

    What is the best approach to read in and XML file and transform to HTML.

    I want to use Razor and not XSLT

    Thanks

  • Euge 23 posts 130 karma points
    Sep 26, 2013 @ 13:08
    Euge
    0

    This is how I managed to solve this.

    FileStream xmlFS = new FileStream(Server.MapPath("/xml/timeline.xml"), FileMode.OpenOrCreate, FileAccess.Read, FileShare.Read);

    System.Xml.XmlReaderSettings settings = new System.Xml.XmlReaderSettings();
    settings.XmlResolver = null;
    settings.DtdProcessing = System.Xml.DtdProcessing.Parse;
    
    // Create the XmlReader object.
    System.Xml.XmlReader reader = System.Xml.XmlReader.Create(xmlFS, settings);    
    
    if (reader != null)
    {
        System.Text.StringBuilder sbXML  = new System.Text.StringBuilder();
    
        while (reader.Read())            
        {
            @sbXML.AppendLine(reader.ReadOuterXml());
        }
    
        // Convert the xml string to a DynamicXml object
        dynamic xmlFeed = Library.ToDynamicXml(sbXML.ToString());
    
        // Retrieve the items
        Umbraco.Core.Dynamics.DynamicXml items = xmlFeed.XPath("/xmlFeed/item");
    
  • Damian Green 452 posts 1433 karma points
    Oct 01, 2013 @ 17:11
    Damian Green
    0

    An alternative I thought of would be to deserialize into a class and output using the object.

  • 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