7
這可能嗎?我無法解決如何做到這一點。是否可以使用架構在XML文檔中定義根元素?
這可能嗎?我無法解決如何做到這一點。是否可以使用架構在XML文檔中定義根元素?
以下應該工作,我也建議在模式的W3學校部分。
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="rootElement" type="RootElementType"/>
<xs:complexType name="RootElementType">
<xs:sequence>
<xs:element name="child1" type="xs:string" minOccurs="1" maxOccurs="unbounded"/>
<xs:element name="child2" type="xs:string" minOccurs="0" maxOccurs="1"/>
</xs:sequence>
<xs:attribute name="user" type="xs:string" use="required"/>
</xs:complexType>
</xs:schema>
這應該是一個XML結構是這樣的模式:
<rootElement user="Bob">
<child1>Hello</child1>
<child1>World</child1>
<child2>Optional</child2>
</rootElement>