Dtd validation with libxml2

2019-06-04 06:54发布

问题:

how do i do dtd validation with libxml2? i am reading my xml file using the reader api. i have an external dtd validation file. how do i perform the validation itself? do i have to convert it to xsd?

回答1:

Use xmlValidateDtd api, as described in FAQ, point 11.

This function is used by xmllint application, when --dtdvalid is supplied. See the source file, xmllint.c, parseAndPrintFile function. Search for xmlValidateDtd, it's used only once now.



回答2:

If your are using python as your programming language, try using lxml. This has in-built implementation of libxml2 which is pretty neat in XML DTD validation. And it provides a lot of information which can be helpful in debugging the dtd or xml file.



标签: xml dtd libxml2