我的問題是關於2個XSD模式,它們必須是XML文檔的基礎。對我來說,首先創建我需要的XML然後創建這些XSD架構會更容易。所以,我在這裏有三個文件。如何將2個xsd模式包含到1個xml文件中?
1 XSD:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.w3schools.com">
<xs:element name="studentAI">
<xs:complexType>
<xs:sequence>
<xs:element name="gender">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="female"/>
<xs:enumeration value="male"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="age">
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:minInclusive value="0"/>
<xs:maxInclusive value="100"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="other" type="desc"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="desc">
<xs:sequence>
<xs:element name="height" type="xs:string"/>
<xs:element name="weight" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
第二XSD:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.w3schools.com">
<xs:element name="group">
<xs:complexType>
<xs:sequence>
<xs:element name="student" minOccurs="2" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="student">
<xs:sequence>
<xs:element name="surname" type="xs:string"/>
<xs:element name="name" type="xs:string"/>
<xs:element name="birthday">
<xs:simpleType>
<xs:restriction base="xs:date"/>
</xs:simpleType>
</xs:element>
<xs:element name="parents" type="parentsDetails"/>
<xs:element name="allCourses" type="allCoursesDetails"/>
</xs:sequence>
<xs:attribute name="id" type="xs:string" use="required"/>
</xs:complexType>
<xs:complexType name="parentsDetails">
<xs:sequence>
<xs:element name="father" type="xs:string"/>
<xs:element name="mother" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="allCoursesDetails">
<xs:sequence>
<xs:element name="course" type="courseDetails" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="courseDetails">
<xs:attribute name="nr" use="required"/>
</xs:complexType>
</xs:schema>
,我需要得到那些2種XSD模式的基礎(對不起,它是空的,但現在當然也有XML文檔必須是信息,它將在該組中不止一個學生):
<group xmlns:xs="http://www.w3schools.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.w3schools.com ">
<student id="1">
<surname></surname>
<name></name>
<birthday></birthday>
<parents>
<father></father>
<mother></mother>
</parents>
<allCourses>
<course nr="01"></course>
<course nr="02"></course>
</allCourses>
<studentAI>
<gender></gender>
<age></age>
<other>
<height></height>
<weight></weight>
</other>
</studentAI>
</student>
</group>
我真的不知道如何包括那些2 X SD模式在我的XML文檔中。我是否應該將它們都包含在XML文檔中,或者我應該首先將第一個XSD模式包含到第二個模塊中(就像結果XML一樣),然後將統一XML模式包含到XML文檔中?以及如何做到這一點?
我最大的問題是關於三個文件的上半部分,其中一個應該放置命名空間的聲明等等。
至於我試圖使用它的程序是氧氣(我有30天lisense)。
我真的希望有人能幫助我。我也希望我的問題很明確。
很多人提前感謝您的幫助!
XML對第二個XSD無效,因爲''不允許有''元素(或者我錯了)?在使用多個XSD時,這些XSD可能有自己的名稱空間,並且可以將名稱空間綁定到XSD。所以你有XSD 1的命名空間A和XSD 2的命名空間B. –
我會創建一個人物,在第一個XSD中給它一個特性,並讓其他特性擴展它 - 學生是一種人,父母是也是人。 –
@Wouter J,謝謝你的關注和評論。是的,'學生'不允許''studentAl'裏面,但我需要結合我的XSD以某種方式,並在他們的基礎上創建我的XML。至於命名空間,我認爲兩個XSD都可以有相同的名稱空間。所以我需要將它們包含到我的XML中 - 這個我不知道該怎麼做... –