Reputation: 292
I need to validate my XML against the well defined schema. The problem is that I normally receive a lot of errors. Had an extensive look of your examples and everything seems to be alright. The problems are as follows:
Multiple annotations found at this line:
- s4s-att-not-allowed: Attribute 'type' cannot appear in element 'attribute'.
- s4s-elt-invalid-content.1: The content of '#AnonType_frominterNodeConnect' is invalid. Element 'attribute' is invalid, misplaced, or
occurs too often.
- src-resolve: Cannot resolve the name 'name' to a(n) 'attribute declaration' component.
Here is the example of XML:
<struct>
<attribute name="sensorReading"/>
<field name="photo" type="integer"/>
<field name="solar" type="integer"/>
<field name="temp" type="real"/>
<field name="humid" type="real"/>
</struct>
Here is the schema that needs to validate it:
<xs:element name="struct">
<xs:complexType>
<xs:sequence>
<xs:element name="field" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute ref="name" type="xs:string" minOccurs="1" maxOccurs="1"/>
<xs:attribute ref="type" type="xs:string" minOccurs="1" maxOccurs="1"/>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute ref="name" type="xs:string" minOccurs="1" maxOccurs="1"/>
</xs:complexType>
</xs:element>
I do not understand why this errors appear. Read somewhere here that attribute needs to be moved at the end of the complex type but this obviously doesn't help much.
Regards to every one that knows where the errors are.
Upvotes: 1
Views: 240
Reputation: 6016
A possible XML Schema to validate that XML is this:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="struct">
<xs:complexType>
<xs:sequence>
<xs:element name="attribute">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="name" use="required" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element name="field" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="name" type="xs:string" use="required" />
<xs:attribute name="type" type="xs:string" use="required" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
¿Why?
As I said in my comment it would be interesting if you read this simple tutorial
Upvotes: 2