Странные бессмысленные ошибки при проверке XML-схемы (самого кода XSD) - PullRequest
1 голос
/ 08 июня 2011

Мне сложно проверить мою схему XML.

Validome Валидатор XML-схемы выдает мне следующую ошибку:

Attribute 'use' is not permitted to appear in element 'xs:attribute'.

для строки

<xs:attribute name="graphtype" use="required">

Меня удивляет, поскольку определено в спецификации как атрибут xsd xs:attribute.

Я попытался определить свои внешние элементы xs:attribute следующим образом:

<xs:attribute name="graphtype">
    ...
</xs:attribute>

и ссылаться на него в своей схеме следующим образом:

<xs:attribute ref="graphtype" use="required" />

Но тогда Validome сообщает мнечто ref недопустимо в xs:attribute, однако name необходимо.Что опять-таки полная чушь в моей книге.

Это мое первое приключение с XML-схемой, так что я немного озадачен.

На заметку: что за дело, в сущности, нет(официальный) XSD-валидатор?
Как я должен проверять XML с помощью XSD , если я не могу проверить свой XSD на первом месте? WTF?
(просто чтобы прояснить: это не настоящий вопрос. Но все же, WTF? )

Вотмоя схема:

<?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" />
                                                <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>

Ответы [ 2 ]

4 голосов
/ 08 июня 2011

Соответствующая часть сообщения об ошибке от этого валидатора, по сути, такова:

Обнаружен недопустимый контент, начиная с элемента 'xs: attribute'.Ожидается один из '{"http://www.w3.org/2001/XMLSchema":element}'.

Другими словами, вы не можете использовать xs:attribute там (внутри xs:all).

Я полагаю, что тогда он решитпродолжайте, предполагая, что вы на самом деле хотели написать xs:element, и вот откуда приходит жалоба на use.

Кстати, ваша ссылка на документацию не относится к реальной спецификации XML-схемы. здесь , хотя его не очень легко понять. В любом случае, он имеет пример рабочего кода для 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>

Обратите внимание, что атрибут находится за пределамиxs:all и прямо под xs:complexType.

1 голос
/ 08 июня 2011

Вы можете найти сообщения об ошибках Saxon более информативными:

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

Существует служба проверки XSD, размещенная W3C. Я не помню URL-адрес случайно. Я бы не назвал его «официальным» - его можно использовать, если вы найдете его полезным.

Кстати, я не люблю нецензурную лексику даже в сокращенном виде.

...