tags:

views:

143

answers:

1

So, I'm trying to use XMLResolver to load an xml file. It works fine when I create an xmlreader from a filename but fails when I do so using a stringreader. It gives me an XslLoadException: XSLT compiler error. The inner exception is "An entry with the same key already exists."

    public override object GetEntity(Uri absoluteUri, string role, Type ofObjectToReturn)
    {
        string f = Path.Combine(@"C:\tmp", Path.GetFileName(absoluteUri.ToString()));
        string testaxCont = @"<xsl:stylesheet xmlns:xsl=""http://www.w3.org/1999/XSL/Transform"" version=""1.0""><xsl:template name=""J""/></xsl:stylesheet>";
        string testaxCont2 = File.ReadAllText(f);
        bool j = testaxCont.Equals(testaxCont2); //This equals true
        XmlReader tmp = XmlReader.Create(new StringReader(File.ReadAllText(f))); //crash
//            XmlReader tmp = XmlReader.Create(f); //don't crash
        return tmp;
    }


testax.xslt    
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"><xsl:include href="testax2.xsl" /></xsl:stylesheet>

testax2.xsl
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"><xsl:template name="J"/></xsl:stylesheet>
+2  A: 

I needed to change the broken line to XmlReader tmp = XmlReader.Create(new StringReader(File.ReadAllText(f)),null,f); With a file it has a base URI but with a string it is missing.

Brian