Is there something radical about this XML schema?

I have only an elementary understanding of the XML schema. This is basically my first interaction with them in any serious way, and I am having some problems. I read on XSD on Google and everything looks up and up with this file.

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="credits"> <xs:complexType> <xs:sequence> <xs:element ref="property" maxOccurs="16" minOccurs="13" /> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="property" type="xs:string"> <xs:complexType> <xs:sequence> <xs:element ref="item" minOccurs="1" maxOccurs="unbounded" /> </xs:sequence> <xs:attribute ref="name" use="required"/> </xs:complexType> </xs:element> <xs:element name="item" type="xs:string"/> <xs:attribute name="name" type="xs:string"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:enumeration value="example1"/> <xs:enumeration value="example2"/> <xs:enumeration value="example3"/> <xs:enumeration value="example4"/> <xs:enumeration value="example5"/> <xs:enumeration value="example6"/> <xs:enumeration value="example7"/> <xs:enumeration value="example8"/> <xs:enumeration value="example9"/> <xs:enumeration value="example10"/> <xs:enumeration value="example11"/> <xs:enumeration value="example12"/> <xs:enumeration value="example13"/> <xs:enumeration value="example14"/> <xs:enumeration value="example15"/> <xs:enumeration value="example16"/> </xs:restriction> </xs:simpleType> </xs:attribute> </xs:schema> 

This is how I download it:

 SchemaFactory schemaFactory = SchemaFactory.newInstance( XMLConstants.W3C_XML_SCHEMA_NS_URI ); Schema schemaXSD = schemaFactory.newSchema( new File ( "test.xsd" ) ); 

I get an exception similar to the following:

org.xml.sax.SAXParseException: src-element.3: The property element has both a type attribute and an anonymous type of the child. Only one of this is allowed for the item.

Thanks for helping SO! Any general guidelines for reading / using schemes created by others are also welcome.: D

+6
xml schema xsd
source share
2 answers

This bit is your problem code:

 <xs:element name="property" type="xs:string"> <xs:complexType> <xs:sequence> <xs:element ref="item" minOccurs="1" maxOccurs="unbounded" /> </xs:sequence> <xs:attribute ref="name" use="required"/> </xs:complexType> </xs:element> 

either remove the type of the outer element ( type="xs:string" ) or delete the anonymous inner element complexType ( <xs:complexType> ... </xs:complexType> )

+5
source share

The property element has both a type attribute and a child of an anonymous type

In other words, you say type="xs:string" , and this prescribes nodes such as <property>foo</property> . But also you put the ComplexType item inside the property , and this prescribes nodes such as <property><item>...</item></property> . This is a contradiction that the parser considers to be a mistake.

If you want to save the number item in each property and one separate line per property , save this line as a separate node, either a child with a tag, or a property attribute. For example. <property mystring="foo"><item>...</item></property>

+6
source share

All Articles