Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XML Validation error -Root element must match doctype

Tags:

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

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

like image 615
Dymond Avatar asked Dec 06 '11 15:12

Dymond


2 Answers

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

like image 188
Quentin Avatar answered Sep 20 '22 18:09

Quentin


<!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">
like image 39
bobince Avatar answered Sep 23 '22 18:09

bobince