How to avoid the "Element" x "in the namespace" x.xsd "has an invalid child element" Elements "in the namespace" x.xsd "?

I have an xml file whose structure is defined by the following xsd:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema targetNamespace="http://schemas.TEST.com/TEST/TEST.xsd" elementFormDefault="qualified" xmlns="http://schemas.TEST.com/TEST/TEST.xsd" xmlns:mstns="http://schemas.TEST.com/TEST/TEST.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="Element">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="Name" type="xs:string" />
        <xs:element name="Items">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="ItemName" type="xs:string" />
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

Now I'm trying to create some test XML data based on previously defined xsd:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<Element xmlns="http://schemas.TEST.com/TEST/TEST.xsd">
   <Name>John Blue</Name>
   <Items>
      <ItemName>test</ItemName>
   </Items>
   <Items>
      <ItemName>test2</ItemName>
   </Items>
   <Items>
      <ItemName>test3</ItemName>
   </Items>
</Element>

This xml file is considered invalid due to duplicate Elements elements. Is there any way around this?

+3
source share
1 answer

What about

<xs:element name="Items" maxOccurs="unbounded">
+7
source

Source: https://habr.com/ru/post/1720130/


All Articles