xmlresolver / xmlresolvercs

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

Support for additional character sets? #1

Closed ndw closed 2 years ago

ndw commented 3 years ago

There's a DataUriTest that relies on the ability to decode ISO-8859-7 characters, but attempting to use that charset throws an exception.

ndw commented 2 years ago

Applications that want to support additional character sets can register a provider, see https://docs.microsoft.com/en-us/dotnet/api/system.text.codepagesencodingprovider.instance?view=net-6.0

You can see this in action in the testDataUriCharset test:

        [Test]
        public void testDataUricharset() {
            string href = "greek.txt";
            string baseuri = "http://example.com/";

            // We don't do this in the resolver, but we do it here to demonstrate that
            // it will work in applications that use the resolver.
            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);

            string line = null;
            ResolvedResource result = resolver.ResolveUri(href, baseuri);
            using (StreamReader reader = new StreamReader(result.GetInputStream())) {
                line = reader.ReadLine();
            }
            Assert.AreEqual("ΎχΎ", line);
        }