Strange nonsense errors on XML Schema validation (of XSD code itself)
I'm having a hard time getting this XML schema of mine to validate.
The Validome XML Schema Validator gives me the following error:
Attribute 'use' is not permitted to appear in element 'xs:attribute'.
for line
<xs:attribute name="graphtype" use="required">
Which makes me wonder as it's defined in the specs to be an xsd attribute of xs:attribute
.
I tried defining my xs:attribute
s externally like this:
<xs:attribute name="graphtype">
...
</xs:attribute>
and referencing it in my schema like this:
<xs:attribute ref="graphtype" use="required" />
But then Validome tells me that ref
is not allowed in xs:attribute
, that name
however is required. Which again is complete bullshit in my book.
This is my first adventure with XML Schema, so I'm kinda stumped.
On a related note: what's the deal with there basically being no (official) XSD validator?
How am I supposed to validate XML with XSD if I can't validate my XSD in first place? WTF? (just to be clear: not meant as a real question. But still, WTF?)Here is my schema:
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://example.com" targetNamespace="http://example.com" elementFormDefault="qualified">
<xs:element name="dlgkml">
<xs:complexType>
<xs:sequence>
<!--graphs-->
<xs:element name="graphs">
<xs:complexType>
<xs:all>
<xs:element name="graph" minOccurs="1">
<xs:complexType>
<xs:all>
<xs:element name="data" type="xs:byte" />
</xs:all>
<xs:attribute name="id" type="xs:nonNegativeInteger" use="required" />
</xs:complexType>
</xs:element>
</xs:all>
</xs:complexType>
</xs:element>
<!--vertices-->
<xs:element name="vertices">
<xs:complexType>
<xs:sequence>
<xs:element name="vertex" minOccurs="1">
<xs:complexType>
<xs:all>
<xs:element name="owners">
<xs:complexType>
<xs:all>
<xs:element name="id" minOccurs="1">
</xs:element>
</xs:all>
</xs:complexType>
</xs:element>
<xs:element name="data" type="xs:byte" />
<xs:attribute name="id" type="xs:nonNegativeInteger" use="required" />
<xs:attribute name="capacity" type="xs:double" default="0.0" />
<xs:attribute name="size" type="xs:double" default="0.0" />
<xs:attribute name="weight" type="xs:double" default="0.0" />
<xs:attribute name="graphtype" use="required">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="hypergraph" />
<xs:enumeration value="graph" />
<xs:enumeration value="tree" />
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:all>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<!--edges-->
<xs:element name="edges">
<xs:complexType>
<xs:sequence>
<xs:element name="edge" minOccurs="1">
<xs:complexType>
<xs:all>
<xs:element name="tail">
<xs:complexType>
<xs:all>
<xs:element name="id" minOccurs="1" />
</xs:all>
</xs:complexType>
</xs:element>
<xs:element name="head">
<xs:complexType>
<xs:all>
<xs:element name="id" minOccurs="1" />
</xs:all>
</xs:complexType>
</xs:element>
<xs:element name="owners">
<xs:complexType>
<xs:all>
<xs:element name="id" minOccurs="1" />
</xs:all>
</xs:complexType>
</xs:element>
<xs:element name="data" type="xs:byte" />
</xs:all>
<xs:attribute name="id" type="xs:nonNegativeInteger" use="required" />
<xs:attribute name="capacity" type="xs:double" default="0.0" />
<xs:attribute name="size" type="xs:double" default="0.0" />
<xs:attribute name="weight" type="xs:double" default="0.0" />
<xs:attribute ref="graphtype" use="required" />
<xs:attribute name="edgetype" use="required">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="undirected" />
开发者_JS百科 <xs:enumeration value="directed" />
<xs:enumeration value="bidirected" />
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
The relevant part of the error message from this validator is, in fact, this:
Invalid content found starting with element 'xs:attribute'. One of '{"http://www.w3.org/2001/XMLSchema":element}' is expected.
In other words, you cannot use xs:attribute
there (inside xs:all
).
I believe it then decides to proceed, assuming that you actually meant to write xs:element
, and that's where the complaint about use
comes from.
Your documentation link is not to the actual XML Schema specification, by the way. That is available here, though it's not particularly easy to comprehend. Anyway, it has a working code sample for xs:all
:
<xsd:complexType name="PurchaseOrderType">
<xsd:all>
<xsd:element name="shipTo" type="USAddress"/>
<xsd:element name="billTo" type="USAddress"/>
<xsd:element ref="comment" minOccurs="0"/>
<xsd:element name="items" type="Items"/>
</xsd:all>
<xsd:attribute name="orderDate" type="xsd:date"/>
</xsd:complexType>
Note that attribute is outside of xs:all
, and directly under xs:complexType
.
You might find Saxon's error messages more informative:
Error at xs:attribute on line 41 column 111 of test.xsd:
Element <xs:attribute> is not allowed as a child of <xs:all>
Error at xs:attribute on line 42 column 104 of test.xsd:
Element <xs:attribute> is not allowed as a child of <xs:all>
Error at xs:attribute on line 43 column 100 of test.xsd:
Element <xs:attribute> is not allowed as a child of <xs:all>
Error at xs:attribute on line 44 column 102 of test.xsd:
Element <xs:attribute> is not allowed as a child of <xs:all>
Error at xs:attribute on line 45 column 87 of test.xsd:
Element <xs:attribute> is not allowed as a child of <xs:all>
Schema processing failed: 5 errors were found while processing the schema
There is an XSD validation service hosted by W3C. I don't recall the URL offhand. I wouldn't describe it as "official" - it's there to use if you find it useful.
By the way, I don't like foul language even in abbreviated form.
精彩评论