我需要向这个 XML 文件添加更多具有相同标题、媒体、描述、创建和显示子元素的“艺术品”元素,我尝试使用 max0ccurs=unbounded 但看到我只能在元素不直接相关的情况下使用它到全局元素。这是 XSD
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xs:element name="Artworks">
<xs:complexType>
<xs:sequence>
<xs:element ref="Artwork"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Artwork">
<xs:complexType>
<xs:sequence>
<xs:element name="Title" type="xs:string"/>
<xs:element name="Media" type="xs:string"/>
<xs:element name="Description" type="xs:string"/>
<xs:element name="Created" type="xs:string"/>
<xs:element name="Display" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
这是 XML
<Artworks xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="artwork1.xsd">
<Artwork>
<Title>Xtreme Air</Title>
<Media>Glass Sculpture</Media>
<Description>An amazing work that uses glass balloon shaps to illustrate a rainbow of balloons circuling a glass earth.</Description>
<Created>April 2010</Created>
<Display>Orlando Museum of Arts</Display>
<Artwork></Artwork>
</Artwork>
</Artworks>
您必须maxOccurs="unbounded"
在第一个模板中添加元素用法定义:
<xs:element name="Artworks">
<xs:complexType>
<xs:sequence>
<xs:element ref="Artwork" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
...
现在你可以Artwork
在你的Artworks
元素中拥有无限的孩子(但不是递归的)。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句