例如,我有 2 个 Xml 模式:
a.xsd:
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="test" targetNamespace="test">
<xsd:include schemaLocation="b.xsd" />
</xsd:schema>`
b.xsd:
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:simpleType name="testType">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="test"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:element name="test" type="testType"/>
</xsd:schema>
第二个模式没有targetNamespace并用作变色龙模式。
我正在尝试使用 XmlSchemaSet 预加载这些模式:
XmlSchemaSet schemaSet = new XmlSchemaSet();
schemaSet.Add(null, @"a.xsd");
foreach (XmlSchema schema in schemaSet.Schemas()) // foreach is used to simplify the example
{
Console.WriteLine("Target namespace: "schema.TargetNamespace); // "Target namespace: test"
XmlSchemaInclude include = (XmlSchemaInclude)schema.Includes[0];
Console.WriteLine("Include target namespace: " + include.Schema.TargetNamespace); // "Include target namespace: test"
}
但是在我这样做之后,两个模式都有“测试”目标命名空间。我希望实例化的模式对象应该等于源模式,但模式“b.xsd”并非如此。为什么它的行为如此,有什么方法可以禁用这种行为?