我有2次XSD的被嵌套:我可以創建一個xml,它指定2個嵌套xsd中的元素而不使用前綴嗎?
DefaultSchema.xsd:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="DefaultSchema"
targetNamespace="http://myNamespace.com/DefaultSchema.xsd"
elementFormDefault="qualified"
xmlns="http://myNamespace.com/DefaultSchema.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
>
<xs:complexType name="ZForm">
<xs:sequence minOccurs="0" maxOccurs="unbounded">
<xs:element name="Part" minOccurs="0" maxOccurs="unbounded" type="Part"/>
</xs:sequence>
<xs:attribute name="Title" use="required" type="xs:string"/>
<xs:attribute name="Version" type="xs:int"/>
</xs:complexType>
<xs:complexType name="Part">
<xs:sequence minOccurs="0" maxOccurs="unbounded">
<xs:element name="Label" type="Label" minOccurs="0"></xs:element>
</xs:sequence>
<xs:attribute name="Title" use="required" type="xs:string"/>
</xs:complexType>
<xs:complexType name="Label">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="Title" type="xs:string"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:schema>
ExportSchema.xsd:(這一個有點包裹1個元件(ZForms)主元件周圍(ZForm在DefaultSchema的)
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="ExportSchema"
targetNamespace="http://myNamespace.com/ExportSchema.xsd"
elementFormDefault="qualified"
xmlns="http://myNamespace.com/DefaultSchema.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:es="http://myNamespace.com/ExportSchema.xsd"
>
<xs:import namespace="http://myNamespace.com/DefaultSchema.xsd" schemaLocation="DefaultSchema.xsd"/>
<xs:element name="ZForms" type="es:ZFormType"></xs:element>
<xs:complexType name="ZFormType">
<xs:sequence>
<xs:element name="ZForm" type="ZForm" maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
</xs:schema>
然後終於)我有一個生成的XML :
<?xml version="1.0" encoding="utf-8"?>
<ZForms xmlns="http://myNamespace.com/ExportSchema.xsd">
<ZForm Version="1" Title="FormTitle">
<Part Title="PartTitle" >
<Label Title="LabelTitle" />
</Part>
</ZForm>
</ZForms>
Visual Studio抱怨它不知道'Part'是什麼。
我希望我不需要使用xml命名空間前綴(..)來使這個XML驗證,因爲ExportSchema.xsd有一個對DefaultSChema.xsd的引用。
有沒有什麼辦法可以使xml結構有效,而無需顯式指定DefaultSchema.xsd?或者這是不行?
這看起來像是朝着良好方向邁出的一步。任何想法爲什麼VS現在不顯示intellisense?另外,我下載了xmlspy(30天試用版),並試着針對(嵌套的)ExportSchma.xsd驗證xml。它一直在抱怨:「無法找到對此文檔實例中支持的模式類型(DTD,W3C模式)的引用」,現在我沒有找到解決方法。 您是否可以驗證xml? – TweeZz
好吧,我找到了正確的'組合':) 我會更新你的答案,並且標記是正確的,因爲你指出我是問題的核心。謝謝! – TweeZz