Re: [xml] XML validation



On Fri, Dec 19, 2008 at 06:47:34PM +0100, Francesco Gennai wrote:
Scenario:

I need to validate an XML file received via e-mail.
It has no <!DOCTYPE element.
The DTD file is stored locally (on the receiving system).
Reading some thread on this list and the documentation I have understood that 
the best validation can be obtained if the DTD file is referenced by the 
XML file.

Since the XML file is a short file, my idea is to add the line

 <!DOCTYPE eulotnw SYSTEM "/dtd/xxxx.dtd">

to the file, before to pass it to 

  xmlCtxtReadFile(pctxt, xmlfilename, NULL, XML_PARSE_DTDVALID);

Is this a good idea to get the best validation of the XML file ?

  That's one possibility, the most correct from an XML perspective
except you need to make some check on where to insert the DTD.

Any other suggestion?

  Do a normal parsing, load the DTd separately with xmlParseDTD
and then do an a posteriori validation of the parsed XML with
xmlValidateDtd(). Search for dtdvalid options and strings in the
xmllint.c code, it does just this.

Daniel

-- 
Daniel Veillard      | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
daniel veillard com  | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library  http://libvirt.org/



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]