XML validation error - Root element must match doctype

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

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

I can’t figure it out.

The idea of ​​my xml file is to keep it as short as possible. I think all this is good, but, as I said, I will not check. Does anyone 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

+8
xml
source share
2 answers

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

 <!DOCTYPE test ^^^^ 

Either modify Doctype to state that root is <A> , or change XML and DTD to use <test> .

+14
source share
 <!DOCTYPE test SYSTEM "test.dtd"> 

Declares that the root of the ELEMENT of the document corresponding to the DTD is called test . Do you want to:

 <!DOCTYPE A SYSTEM "test.dtd"> 
+4
source share

All Articles