0

I am writing an XML parser in C++ using libxml library which requires me to validate the XML against a DTD which is specified inline. I don't want to use system() in my program. Otherwise I could have used the xmllint command.

I came across the xmlValidateDtd(xmlValidCtxtPtr ctxt, xmlDocPtr doc, xmlDtdPtr dtd) function specified in the http://xmlsoft.org/ API page. But I feel it is DOM based function since in SAX parsing there is no xmlDocPtr.

Are there are any other methods to validate the XML document against the inline DTD?

gunner4evr
  • 79
  • 7
  • Your question confuses me. You're writing "an XML parser" using a library that already performs XML parsing? In what sense, then, are you writing a parser? – C. M. Sperberg-McQueen Jun 06 '14 at 16:57
  • You are right. The library parses the XML and calls the registered functions based on events. Handling the elements, attributes etc. according the specific XML, needs to be taken care inside the registered functions. Defining these functions, is what I meant by writing an XML parser. – gunner4evr Jun 07 '14 at 18:38

1 Answers1

0

Usually, you simply provide the XML_PARSE_DTDVALID parser option, so the document will be validated when parsed.

If the document has already been parsed without validation, you can use xmlValidateDocument:

int xmlValidateDocument (xmlValidCtxtPtr ctxt, 
                         xmlDocPtr doc)

Try to validate the document instance basically it does the all the checks described by the XML Rec i.e. validates the internal and external subset (if present) and validate the document tree.

ctxt: the validation context
doc: a document instance
Returns:1 if valid or 0 otherwise

nwellnhof
  • 32,319
  • 7
  • 89
  • 113