I need to create XML from this XSD:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="group">
<xs:complexType>
<xs:sequence>
<xs:element name="person" minOccurs="5" maxOccurs="20" type="xs:string"/>
</xs:sequence>
<xs:attribute name="name" use="required" type="xs:string"/>
</xs:complexType>
</xs:element>
</xs:schema>
Here is the XML I've tried:
<?xml version="1.0" ?>
<group name="abcd">
xmlns="www.example.org"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="ex1.xsd">
<person>Joao</person>
<person>Andre</person>
<person>Filipe</person>
<person>Joaquim</person>
<person>Rui</person>
</group>
I am getting this error:
Not valid. Error - Line 10, 9: org.xml.sax.SAXParseException; lineNumber: 10; columnNumber: 9; cvc-complex-type.2.3: Element 'group' cannot have character [children], because the type's content type is element-only.
Change the 'group' definition in XSD to include mixed="true"
Number of issues:
group
tag. This is the direct cause of your immediate error. It causes the parser to misinterpret what you intend to be attributes as text content to thegroup
element.schemaLocation
must take namespace-XSD pairs.elementFormDefault="qualified"
Altogether, the following XSD will validate the following XML successfully.
XSD
XML