Tuesday, June 24, 2008

"Invalid URI: The Uri scheme is too long" - now that's a peculiar message. I got it while doing some Xslt transformations. It comes out that XslCompiledTransform can't just read any xml and transform it. There are issues if Uri scheme is too long. What is too long? Can't really tell, since mine wasn't THAT long.

The following code did not work for me:

XslCompiledTransform xsl = new XslCompiledTransform();
xsl.Load("t.xsl");
XmlWriter writer = XmlWriter.Create("dest.xml");
xsl.Transform(File.ReadAllText("source.xml"), writer);

So I had to use this one:

XslCompiledTransform xsl = new XslCompiledTransform();
xsl.Load("t.xsl");
using (XmlWriter writer = XmlWriter.Create("dest.xml"))
{
    using (XmlReader reader = XmlReader.Create("source.xml"))
    {
        xsl.Transform(reader, writer);
    }
}

The problem is the Transform method and File.ReadAllText that returns the whole source xml string at once. XslCompiledTransform just can't handle it for some reason.

Name
E-mail
Home page

Comment (Some html is allowed: a@href@title, strike) where the @ means "attribute." For example, you can use <a href="" title=""> or <blockquote cite="Scott">.  

Enter the code shown (prevents robots):

Live Comment Preview