你没有真正提供足够的信息。正如Michael指出的那样,您不能从complexType定义中创建XML元素。
但无论哪种情况下是有效的给予正确的模式。
我还要指出的是,这个样本中的xmlns:NS1 =“MySecondNS”语句什么都不做,它只是声明命名空间。一旦宣布它不被使用。
<SomeType xmlns="MyRootNs" xmlns:ns1="MySecondNS">
<SomeElement>
...
</SomeElement>
</SomeType>
例
如果你的模式是这样的
<?xml version="1.0" encoding="utf-8" ?>
<!--Created with Liquid XML 2017 Developer Bundle Edition (Trial) 15.0.0.6978 (https://www.liquid-technologies.com)-->
<xs:schema elementFormDefault="qualified" targetNamespace="http://MyNamespce1" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:q1="http://MyNamespce1">
<xs:complexType name="SomeType">
<xs:sequence>
<xs:element name="SomeElement" type="q1:SomeType" minOccurs="0" />
</xs:sequence>
</xs:complexType>
<xs:element name="MyRoot" type="q1:SomeType" />
</xs:schema>
然后有效的XML是这样的
<?xml version="1.0" encoding="utf-8"?>
<!-- Created with Liquid XML 2017 Developer Bundle Edition (Trial) 15.0.0.6978 (https://www.liquid-technologies.com) -->
<MyRoot xmlns="http://MyNamespce1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://MyNamespce1 Schema.xsd">
<SomeElement>
<SomeElement>
<SomeElement></SomeElement>
</SomeElement>
</SomeElement>
</MyRoot>
或
<?xml version="1.0" encoding="utf-8"?>
<!-- Created with Liquid XML 2017 Developer Bundle Edition (Trial) 15.0.0.6978 (https://www.liquid-technologies.com) -->
<ns:MyRoot xmlns:ns="http://MyNamespce1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://MyNamespce1 Schema.xsd">
<ns:SomeElement>
<ns:SomeElement>
<ns:SomeElement></ns:SomeElement>
</ns:SomeElement>
</ns:SomeElement>
</ns:MyRoot>
的命名空间的规则是一个单一的文件中相当简单,但与被inlucded或导入多个模式文件打交道时得到相当复杂。在尝试理解import/include对命名空间的影响之前,我建议您理解规则应用于单个模式。
而且它会帮助,如果你在未来提供更完整的样本。