Я создаю схему XSD для проверки XML-файла.
Схема верна для страницы проверки W3C XML Schema (XSD) , тогда как для QXmlSchema есть ошибка.Это минимальная часть XSD, которая генерирует ошибку:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://standards.ieee.org/IEEE1516-2010" xmlns:ns="http://standards.ieee.org/IEEE1516-2010" targetNamespace="http://standards.ieee.org/IEEE1516-2010" elementFormDefault="qualified" attributeFormDefault="unqualified" version="2010">
<xs:element name="objectModel" type="objectModelType">
</xs:element>
<xs:complexType name="objectModelType">
<xs:sequence>
<xs:element name="modelIdentification" type="modelIdentificationType">
<xs:annotation>
<xs:documentation>documents certain key identifying information within the object model description</xs:documentation>
</xs:annotation>
</xs:element>
<xs:any namespace="##other" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="modelIdentificationType">
<xs:sequence>
<xs:element name="name" type="NonEmptyString">
<xs:annotation>
<xs:documentation>specifies the name assigned to the object model</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="glyph" minOccurs="0">
<xs:annotation>
<xs:documentation>specifies a glyph to visually represent the model</xs:documentation>
</xs:annotation>
<xs:complexType mixed="true">
<xs:simpleContent>
<xs:extension base="glyphType"/>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:any namespace="##other" minOccurs="0"/>
</xs:sequence>
<xs:attributeGroup ref="commonAttributes"/>
</xs:complexType>
<xs:complexType name="String">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attributeGroup ref="commonAttributes"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<xs:complexType name="NonEmptyString">
<xs:simpleContent>
<xs:extension base="nonEmptyString">
<xs:attributeGroup ref="commonAttributes"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<xs:complexType name="glyphType" mixed="true">
<xs:simpleContent>
<xs:extension base="xs:base64Binary">
<xs:attributeGroup ref="commonAttributes"/>
<xs:attribute name="href" type="xs:anyURI"/>
<xs:attribute name="type" type="glyphTypeUnion"/>
<xs:attribute name="height" type="xs:short"/>
<xs:attribute name="width" type="xs:short"/>
<xs:attribute name="alt" type="xs:string"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<xs:complexType name="IdentifierType">
<xs:simpleContent>
<xs:extension base="xs:NCName">
<xs:attributeGroup ref="commonAttributes"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<xs:simpleType name="nonEmptyString">
<xs:restriction base="xs:string">
<xs:minLength value="1"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="glyphTypeUnion">
<xs:union memberTypes="glyphTypeEnumerations xs:string"/>
</xs:simpleType>
<xs:simpleType name="glyphTypeEnumerations">
<xs:restriction base="xs:string">
<xs:enumeration value="BITMAP"/>
<xs:enumeration value="JPG"/>
<xs:enumeration value="GIF"/>
<xs:enumeration value="PNG"/>
<xs:enumeration value="TIFF"/>
</xs:restriction>
</xs:simpleType>
<xs:attributeGroup name="commonAttributes">
<xs:attribute name="notes" type="xs:IDREFS" use="optional"/>
<xs:attribute name="idtag" type="xs:ID" use="optional"/>
<xs:anyAttribute namespace="##other"/>
</xs:attributeGroup>
</xs:schema>
Если я копирую и вставляю эту схему на страницу W3C, она говорит, что все в порядке.
Я создаю схему в своей программетаким образом:
QXmlSchema schema;
// text is a char array containing the XML file.
schema.load(text);
Когда я вызываю метод load
, в окне консоли отладки появляется следующее сообщение:
Error XSDError in Unknown location, at line 52, column 22: complexType element with simpleContent child element must not have a mixed attribute.
Если перейти к номеру строки, показанному наСообщение Я вижу, что complexType является следующим:
<xs:complexType name="glyphType" mixed="true">
<xs:simpleContent>
<xs:extension base="xs:base64Binary">
<xs:attributeGroup ref="commonAttributes"/>
<xs:attribute name="href" type="xs:anyURI"/>
<xs:attribute name="type" type="glyphTypeUnion"/>
<xs:attribute name="height" type="xs:short"/>
<xs:attribute name="width" type="xs:short"/>
<xs:attribute name="alt" type="xs:string"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
Сообщение об ошибке мне кажется ясным, когда я вижу эту часть XSD, но я не знаю, почему это должно быть ошибкой.
Так что для страницы W3C это правильно, для Qt неправильно.Какой из них имеет правильную интерпретацию сложного типа с простым содержимым?
Это минимальный пример XML, который должен быть проверен (он есть на веб-странице):
<?xml version="1.0" encoding="utf-8"?>
<objectModel xmlns="http://standards.ieee.org/IEEE1516-2010" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://standards.ieee.org/IEEE1516-2010 http://standards.ieee.org/downloads/1516/1516.2-2010/IEEE1516-DIF-2010.xsd">
<modelIdentification>
<name>New</name>
</modelIdentification>
</objectModel>