XML Validation error -Root element must match doct

2020-08-20 11:27发布

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

i cant figure this out.

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 ?

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>

And my 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)>

Thanks

标签: xml
2条回答
对你真心纯属浪费
2楼-- · 2020-08-20 11:47
<!DOCTYPE test SYSTEM "test.dtd">

Declares that the root ELEMENT of the DTD-conformant document is called test. You want:

<!DOCTYPE A SYSTEM "test.dtd">
查看更多
迷人小祖宗
3楼-- · 2020-08-20 11:52

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

<!DOCTYPE test
          ^^^^

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

查看更多
登录 后发表回答