例如,我有两个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“来说不是这样。为什么它会这样做,是否有任何方法来禁用这样的行为?
发布于 2013-02-12 19:11:52
当您包含来自a.xsd的a.xsd时,您实际上是说您希望b.xsd具有与a.xsd相同的目标命名空间。如果模式文档(如b.xsd)没有目标命名空间的规范,则变色龙包括表示发生这种情况的过程。
如果希望test元素和在b.xsd中声明的testType类型不存在于名称空间test中,则不希望将b.xsd用作变色龙,并且不应包括a.xsd中的b.xsd。您可能希望使用xs:import。
但也许我不明白你在追求什么。
https://stackoverflow.com/questions/14839726
复制相似问题