xmlresolver / xmlresolvercs

A C# implementation of the XML Resolver
Other
4 stars 3 forks source link

Should resolving https://www.w3.org/TR/xslt-30/schema-for-xslt30.xsd work? #48

Closed martin-honnen closed 2 years ago

martin-honnen commented 2 years ago

When I run

using System;
using System.Xml;
using Org.XmlResolver;
using Org.XmlResolver.Features;

namespace XmlResolverTest2XSLT30Schema
{
    class Program
    {
        static void Main(string[] args)
        {
            var resolverConfig = new XmlResolverConfiguration();
            resolverConfig.SetFeature(ResolverFeature.ASSEMBLY_CATALOGS, "XmlResolverData.dll");

            var resolver = new Resolver(resolverConfig);

            string uri = "https://www.w3.org/TR/xslt-30/schema-for-xslt30.xsd";

            Console.WriteLine(resolver.ResolveUri(null, uri));

            using (XmlReader xmlReader = XmlReader.Create(uri, new XmlReaderSettings() { DtdProcessing = DtdProcessing.Parse, XmlResolver = resolver, Async = false}))
            {
                while (xmlReader.Read())
                {
                    Console.WriteLine(xmlReader.ReadOuterXml());
                }
            }
        }
    }
}

I get (.NET 5, Windows 10)

System.Xml.XmlException HResult=0x80131940 Nachricht = Cannot resolve 'https://www.w3.org/TR/xslt-30/schema-for-xslt30.xsd'. Quelle = System.Private.Xml Stapelüberwachung: at System.Xml.XmlTextReaderImpl.FinishInitUriString() at System.Xml.XmlTextReaderImpl..ctor(String uriStr, XmlReaderSettings settings, XmlParserContext context, XmlResolver uriResolver) at System.Xml.XmlReaderSettings.CreateReader(String inputUri, XmlParserContext inputContext) at System.Xml.XmlReader.Create(String inputUri, XmlReaderSettings settings) at XmlResolverTest2XSLT30Schema.Program.Main(String[] args) in C:\Users\marti\SomePath\XmlResolverTest2XSLT30Schema\Program.cs:line 21

Any idea whether that should work?

ndw commented 2 years ago

Yes, I think that should.

ndw commented 2 years ago

The problem is that URI_FOR_SYSTEM is initially false. The catalog says (correctly) that an XSD file is a URI and not an XML system identifier. But the .NET parser only has an "EntityResolver" and that, naturally, only searches for system and public identifiers because that's how entities are identified.

If you enable URI_FOR_SYSTEM:

            resolverConfig.SetFeature(ResolverFeature.URI_FOR_SYSTEM, true);

You're telling the resolver to treat URI entries like system entries for the purpose of resolution and then it works.

Trouble is, shipping the resolver with that set to false sort of makes the data assembly less useful.

I expect I should bump the version and change the default.