XmlSchemaSet compile() call fills included schema TargetNamespace
-
Tuesday, February 05, 2013 5:11 PM
Hi everybody,
I have following schemas:
- infrastructureRoot.xsd
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:mif="urn:hl7-org:v3/mif" xmlns:v3="urn:hl7-org:v3" xmlns:ex="urn:hl7-org/v3-example" xmlns="urn:hl7-org:v3" targetNamespace="urn:hl7-org:v3" elementFormDefault="unqualified"> <xs:include schemaLocation="datatypes-base.xsd"/> <xs:group name="InfrastructureRootElements"> <xs:sequence> <xs:element name="realmCode" type="Norwegian_customer" minOccurs="0" maxOccurs="unbounded"/> </xs:sequence> </xs:group> <xs:attributeGroup name="InfrastructureRootAttributes"/> </xs:schema>
- datatypes-base.xsd
<?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:sch="http://www.ascc.net/xml/schematron" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="unqualified"> <xs:complexType name="customer"> <xs:sequence> <xs:element name="firstname" type="xs:string"/> <xs:element name="lastname" type="xs:string"/> <xs:element name="country" type="xs:string"/> </xs:sequence> </xs:complexType> <xs:complexType name="Norwegian_customer"> <xs:complexContent> <xs:restriction base="customer"> <xs:sequence> <xs:element name="firstname" type="xs:string"/> <xs:element name="lastname" type="xs:string"/> <xs:element name="country" type="xs:string" fixed="Norway"/> </xs:sequence> </xs:restriction> </xs:complexContent> </xs:complexType> </xs:schema>I use following code for load the root schema:
using System; using System.IO; using System.Xml; using System.Xml.Schema;
using System.Diagnostics; namespace Test { public class DummyReader : TextReader { public override int Peek() { return -1; } public override int Read() { return -1; } public override int Read(char[] buffer, int index, int count) { return 0; } public override int ReadBlock(char[] buffer, int index, int count) { return 0; } public override string ReadToEnd() { return String.Empty; } public override string ReadLine() { return null; } } class Program { [STAThread] static void Main(string[] args) { Func<XmlReader> xmlReaderFactory = () => { XmlReaderSettings schemaReaderSettings = new XmlReaderSettings{ DtdProcessing = DtdProcessing.Parse}; XmlTextReader reader = new XmlTextReader(@"InfrastructureRoot.xsd"); return XmlReader.Create(reader, schemaReaderSettings); }; XmlSchema xsd = XmlSchema.Read(xmlReaderFactory(), (sender, eventArgs) => {}); XmlSchemaSet schemaSet = new XmlSchemaSet(); schemaSet.ValidationEventHandler += (sender, eventArgs) => Console.WriteLine(eventArgs.Message + " " + eventArgs.Severity); try { try { XmlReaderSettings schemaReaderSettings = new XmlReaderSettings {DtdProcessing = DtdProcessing.Parse}; XmlReader schemaReader = XmlReader.Create(new DummyReader(), schemaReaderSettings); schemaSet.Add(null, schemaReader); } catch { // the only thing this code is needed is to set ProhibitDTD to false // there is no acceptable public way to do that } schemaSet.Add(xsd); schemaSet.Compile(); XmlSchemaInclude external = ((XmlSchemaInclude)xsd.Includes[0]); String targetNamespace = external.Schema.TargetNamespace;
Debug.Assert(targetNamespace == null); } catch{} } } }
After execution "targetNamespace" value equals "urn:hl7-org:v3" , which is not true for original original schema "datatypes-base.xsd" and produce validation errors. Can someone help me with solution?
- Edited by Konstantyn Varlamov Tuesday, February 05, 2013 5:13 PM
- Edited by Konstantyn Varlamov Tuesday, February 05, 2013 5:19 PM
- Edited by Konstantyn Varlamov Tuesday, February 05, 2013 5:22 PM
- infrastructureRoot.xsd

