1

所以,我正在尝试使用 XMLResolver 来加载一个 xml 文件。当我从文件名创建 xmlreader 时它工作正常,但当我使用 stringreader 时失败。它给了我一个XslLoadException: XSLT compiler error.内在的例外是"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>
4

1 回答 1

3

我需要将虚线更改为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。

于 2009-05-27T15:42:38.620 回答