问题
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.
来源:https://stackoverflow.com/questions/4594049/dtd-validation-with-libxml2