繁体   English   中英

XML模式问题:重复元素不重复

[英]XML schema issue: Repeating Element not repeating

我有一个漂亮的标准xml模式,该模式定义了一个应该重复的名为“ part”的元素。

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:element name="part">
  <xs:complexType>
   <xs:sequence>
   <xs:element name="part_number" type="xs:string"/>
   <xs:element name="price" type="xs:decimal"/>
  </xs:sequence>
 </xs:complexType>
</xs:element>

</xs:schema>

问题是,当我使用此架构导出价格表时,得到以下信息:

<?XML version="1.0" encoding="UTF-8" standalone="yes"?>
<part>
<part_number>10-000</part_number>
<price>151.8</price>
</part>

当我想要多个<part>元素时。 我在架构中哪里搞砸了?

  <xs:element name="parts">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="part" maxOccurs="unbounded" minOccurs="0">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="part_number" type="xs:string"/>
              <xs:element name="price" type="xs:decimal"/>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>

http://www.w3schools.com/schema/schema_example.asp

您的元素需要maxOccurs =“ unbounded”,因为maxOccurs的默认值为1。

<xs:element name="part" maxOccurs="unbounded">

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM