开发者

XML validation fails with error "Top level is not completed"

I've got what seems like a very simple example of an xsd and xml file where the xml file does not validate.

Copies of the two files are below.

The first xml element with id = 'fixMe' gets an error that says Top level is not completed. Valid xml document must have a root tag

If I remove its id attribute or use "idx" instead of "id", it's fine. But I can't figure out why. 'id' should be a valid attribute.

Any insight appreciated.

XML:

<question id="fixMe" />
<question idx="ok"/>
<question />

XSD:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema version="1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema"
           targetNamespace="perceptive.com/mi/analysis"
           xmlns="perceptive.com/mi/analysis"
           elementFormDefault="qualified" attributeFormDefault="unqualified">

<xs:element name="test开发者_如何学Python" type="test"/>

<xs:complexType name="test">
    <xs:sequence minOccurs="1" maxOccurs="10">
        <xs:element name="question" type="question_type"/>
    </xs:sequence>
</xs:complexType>

<xs:complexType name="question_type">
    <xs:attribute name="idx" type="xs:string" use="optional"/>
    <xs:attribute name="id"  type="xs:string" use="optional"/>
</xs:complexType>

</xs:schema>


An XML document cannot be valid until it is well-formed.

So you should specify a root tag in XML document, e.g.:

<root>
    <question id="fixMe" />
    <question idx="ok"/>
    <question />
</root>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜