简体   繁体   中英

XML Validation error -Root element must match doctype

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM