XML 验证错误 - 根元素必须与文档类型匹配 [英] XML Validation error -Root element must match doctype

查看:34
本文介绍了XML 验证错误 - 根元素必须与文档类型匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用外部 DTD 验证我的 XML 文件.但我每次都会收到这个错误.

Im trying to validate my XML file with an external DTD. But I get this error everytime.

Document root element "A", must match DOCTYPE root "test".

我想不通.

我的 xml 文件的想法是它需要尽可能短.我认为这一切都很好,但就像我说的,我不会验证.有人有想法吗?

The idea of my xml file is that its need to be as short as possible . I thinkt its all good but like i said, i wont validate. Does someone have an idea ?

这是我的 XML 文件

This is my XML file

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE test SYSTEM "test.dtd">

<A>
<B>
<F>name</F>
</B>
<D>lastname</D>
<F>name</F>
</A>

还有我的 DTD

<!ELEMENT A (B, (C|D), E?, (F, G?)+)>
<!ELEMENT B (F|G)+>
<!ELEMENT D (#PCDATA|C)*>
<!ELEMENT F (#PCDATA)>
<!ELEMENT G (#PCDATA)>
<!ELEMENT C (#PCDATA)>
<!ELEMENT E (#PCDATA)>

谢谢

推荐答案

Doctype 声称根元素是 但你已经使用了

The Doctype claims the root element is <test> but you have used <A>

<!DOCTYPE test
          ^^^^

要么更改 Doctype 使其声称根为 ,要么更改 XML 和 DTD 以使用 .

Either change the Doctype so it claims the root is <A> or change the XML and DTD to use <test>.

这篇关于XML 验证错误 - 根元素必须与文档类型匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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