XML验证失败,并显示错误“顶级未完成". [英] XML validation fails with error "Top level is not completed"

查看:151
本文介绍了XML验证失败,并显示错误“顶级未完成".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个看起来非常简单的xsd和xml文件示例,其中xml文件未通过验证.

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.

id ='fixMe'的第一个xml元素出现错误,提示 顶层尚未完成. 有效的xml文档必须具有根标记

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

如果我删除其id属性或使用"idx"而不是"id",就可以了.但我不知道为什么. "id"应该是有效的属性.

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.

任何见识表示赞赏.

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

推荐答案

一个XML文档只有格式正确才能有效.

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

因此,您应该在XML文档中指定一个根标记,例如:

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

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

这篇关于XML验证失败,并显示错误“顶级未完成".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆