mirror of
https://github.com/BepInEx/mono.git
synced 2026-11-16 01:41:18 -10:00
Fix bug #13716 - use XmlSchemaSettings.XmlResolver to resolve schemas.
This commit is contained in:
1 parent
5c55eea17e
commit
2cc36e3331
2 files changed
+39
-8
No files matched your search
@@ -130,14 +130,10 @@ namespace System.Xml.Schema
|
||||
|
||||
public XmlSchema Add (string targetNamespace, string schemaUri)
|
||||
{
|
||||
XmlTextReader r = null;
|
||||
try {
|
||||
r = new XmlTextReader (schemaUri, nameTable);
|
||||
return Add (targetNamespace, r);
|
||||
} finally {
|
||||
if (r != null)
|
||||
r.Close ();
|
||||
}
|
||||
var uri = xmlResolver.ResolveUri (null, schemaUri);
|
||||
using (var stream = (Stream) xmlResolver.GetEntity (uri, null, typeof (Stream)))
|
||||
using (var r = XmlReader.Create (stream, new XmlReaderSettings () { XmlResolver = xmlResolver, NameTable = nameTable}))
|
||||
return Add (targetNamespace, r);
|
||||
}
|
||||
|
||||
public XmlSchema Add (string targetNamespace, XmlReader schemaDocument)
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Xml;
|
||||
using System.Xml.Schema;
|
||||
using NUnit.Framework;
|
||||
@@ -279,6 +280,40 @@ type=""xsd:string"" use=""required""/>
|
||||
xss.Compile ();
|
||||
Assert.IsNotNull (xss.GlobalElements [new XmlQualifiedName ("GetSystemDateAndTimeResponse", "http://www.onvif.org/ver10/device/wsdl")], "#1");
|
||||
}
|
||||
|
||||
[Test] // bug #13716
|
||||
public void ResolveSchemaUriUsingXmlResolver ()
|
||||
{
|
||||
var resolver = new Bug13716XmlResolver ();
|
||||
string xml = "<people xmlns='testschema'><person name='Ian'><books><book>Clean Code</book></books></person></people>";
|
||||
string ns = "testschema";
|
||||
string xsdPath = "my.xsd";
|
||||
|
||||
var readerSettings = new XmlReaderSettings ();
|
||||
|
||||
//readerSettings.XmlResolver = resolver;
|
||||
readerSettings.Schemas.XmlResolver = resolver;
|
||||
readerSettings.Schemas.Add (ns, xsdPath);
|
||||
readerSettings.ValidationType = ValidationType.Schema;
|
||||
|
||||
using (var xr = XmlReader.Create (new StringReader (xml), readerSettings))
|
||||
{
|
||||
while (!xr.EOF)
|
||||
xr.Read ();
|
||||
}
|
||||
}
|
||||
|
||||
public class Bug13716XmlResolver : XmlUrlResolver
|
||||
{
|
||||
public override object GetEntity(Uri absoluteUri, string role, Type typeOfObjectToReturn)
|
||||
{
|
||||
string xsd = @"
|
||||
<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' targetNamespace='testschema'>
|
||||
<xs:element name='people' />
|
||||
</xs:schema>";
|
||||
return new MemoryStream (Encoding.UTF8.GetBytes (xsd));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
Reference in new issue
Block a user