My question relates to defining an XSD document. My specific issue is how to define the XSD so that when the XML is generated an element will have type="array".
Desired result would be something like:
<names type="array">
<name>
......
</name>
</names>
I have experimented using methods recommended on several forums, but from I have found it seems to me like there may not even be a type for array, which confuses me since a resulting XML element can have a type of array.
There are tools that will take an XSD and generate a sample XML document that adheres to the XSD, but you should understand that the primary purpose of an XSD is to validate an 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 using a type="array"
attribute-value pair is unconventional in the XML as type information is conveyed in the XSD in the content model for names
and needn't be repeated explicitly in the XML document.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With