Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there something radically wrong with this XML Schema?

Tags:

xml

schema

xsd

I have only an elementary understanding of XML Schema. This is basically my first interaction with them in any serious way and I'm having some issues. I've read up on XSDs on google and everything looks on the 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>

Here's how I'm loading it:

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

I'm getting an exception like the following:

org.xml.sax.SAXParseException: src-element.3: Element 'property' has both a 'type' attribute and a 'anonymous type' child. Only one of these is allowed for an element.

Thanks for the help SO! Any general advice on reading/using schemas created by others is also appreciated! :D

like image 422
bobber205 Avatar asked Mar 02 '11 01:03

bobber205


People also ask

How do I solve the XML to schema Wizard schema error?

If you are using the XML to Schema Wizard, this error can occur if you infer schemas more than one time from the same source. In this case, you can remove the existing XSD schema files from the project, add a new XML to Schema item template, and then provide the XML to Schema Wizard with all the applicable XML sources for your project.

Why are XML schemas extensible?

XML Schemas are extensible, because they are written in XML. When sending data from a sender to a receiver, it is essential that both parts have the same "expectations" about the content. With XML Schemas, the sender can describe the data in a way that the receiver will understand.

How do XML schemes work?

When sending data from a sender to a receiver, it is essential that both parts have the same "expectations" about the content. With XML Schemas, the sender can describe the data in a way that the receiver will understand. A date like: "03-11-2004" will, in some countries, be interpreted as 3.November and in other countries as 11.March.

How can I get more detailed error information for XSD files?

You may be able to get more detailed error information if you ensure that the XML namespaces for the .xsd files included in your project match the XML namespaces identified for the XML Schema set in Visual Studio.


1 Answers

Element 'property' has both a 'type' attribute and a 'anonymous type' child

In other words, you say type="xs:string" and this prescribes nodes like <property>foo</property>. But also you put a ComplexType item inside the property, and this prescribes nodes like <property><item>...</item></property>. This is the contradiction which the parser considers an error.

If you want to store a number of items in each property and one separate string per property, store this string as separate node, either a child with a tag, or an attribute of property. E.g. <property mystring="foo"><item>...</item></property>

like image 70
9000 Avatar answered Nov 12 '22 18:11

9000