XSD definition so the XML element will be type = "array"

My question is related to the definition of an XSD document. My specific problem is how to define an XSD so that when generating XML the element has type = "array".

The desired output will look something like this:

<names type="array">
  <name>
  ......
  </name>
</names>

      

I experimented with the methods recommended in several forums, but from what I found, it seems to me that it might not even be an array type, which confuses me since the resulting XML element may be of an array type.

+3


source to share


1 answer


There are tools that will take an XSD and generate a sample XML document that will adhere to the XSD, but you must understand that the main purpose of XSD is to validate the XML document.

This XSD will validate your XML document:



<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="names">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="name" maxOccurs="unbounded"/>
      </xs:sequence>
      <xs:attribute name="type"/>
    </xs:complexType>
  </xs:element>
</xs:schema>

      

Note also that the use of an attribute-value pair type="array"

is unconventional in XML because type information is passed to the XSD in the content model for names

and does not need to be explicitly repeated in the XML document.

+1


source







All Articles