Copied to clipboard

Flag this post as spam?

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


  • DrewJigsaw 12 posts 29 karma points
    Feb 10, 2011 @ 15:06
    DrewJigsaw
    0

    Parsing XML using XSLT in /base

    Hello everyone,
    I've been working on a /base routine that will in theory ingest xml from an external source parse that xml via xslt and chuck out nicely formed xml at the other end. Trouble is I'm still quite new to C# .net development and I'm having to feel my way around the problem.

    This is what I have so far.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using umbraco.presentation.umbracobase;
    using umbraco.presentation.Web;
    using System.Xml.XPath;
    using System.Xml;
    using System.Xml.Xsl;


    namespace GeckoBoard.XMLProcessings
    {
        public class Library
        {
            public static XPathNodeIterator Test()
            {
                XmlDocument document = new XmlDocument();
    //Fetch XML over HTTP
                document.Load("http://api.getclicky.com/api/stats/4?site_id=66353141&sitekey=73ba7921526acd12&type=visitors-list&visitor-details=time,uid&date=today&limit=all");

                XslCompiledTransform xslt = new XslCompiledTransform();

    //Load in XSLT (a local path would be better I think?)
                xslt.Load("http://mydomaine/xslt/Test.xslt");

                XmlDocument transform = new XmlDocument();

    //Attempt to pass in the XML document into the transform
                using (XmlWriter writer = transform.CreateNavigator().AppendChild())
                {
                    xslt.Transform(document, null, writer);
                }

    //Return the output
                XPathNodeIterator output = transform.CreateNavigator().Select("/");
                return output;
            }
        }
    }

    At pressent I'm getting an inner exception of "System.IO.IOException: Unable to read data from the transport connection"

    Any ideas anyone has are welcome =)

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Feb 10, 2011 @ 16:29
    Jeroen Breuer
    0

    It seems this error is unrelated to outputting xml with /base. I think the error is in document.load or xslt.load.

    Btw in Umbraco 4.6 you can also output an XmlDocument or XDocument. See this topic: http://our.umbraco.org/forum/developers/api-questions/12058-XPathNodeIterator-loses-CDATA

    Jeroen

  • DrewJigsaw 12 posts 29 karma points
    Feb 10, 2011 @ 16:40
    DrewJigsaw
    0

    Thanks for the infomation on XDocument, that could really be useful.

    I did had a feeling the error may be with xslt.load I did try a, for want of a better word, local path but that reasult in a load error also.
    When I input

    xslt.Load("text.xstl");

    I recieved an error that file could not be located at location on the C:// but it bore little resemblece to the location of the file. Is there a better way to specify the location of a local file within a load statement?

Please Sign in or register to post replies

Write your reply to:

Draft