[xml] XML Validation using DTD:



Hi ,

I am new to XML Parsing. I was supposed to Parse XML Doc , I did that using libxml DOM parser. But now i need to do it's validation also using DTD , My queries are:

1). According to me DTD using which validation is to be specified in XML file itself. Is it possible , DTD file need not be specified in XML File and still be used for validation purpose.?



<?xml version="1.0"?>

<!DOCTYPE Sample SYSTEM "d.dtd">



2). I know of API xmlCtxtReadFile to get a ctxt for XML file and then check the validity of

ctxt->valid to know if File has passed validation or not.

Consider this :
static void
exampleFunc(const char *filename) {
   xmlParserCtxtPtr ctxt; /* the parser context */
   xmlDocPtr doc; /* the resulting document tree */
   /* create a parser context */
   ctxt = xmlNewParserCtxt();
   if (ctxt == NULL) {
       fprintf(stderr, "Failed to allocate parser context\n");
   /* parse the file, activating the DTD validation option */
   doc = xmlCtxtReadFile(ctxt, filename, NULL, XML_PARSE_DTDVALID);
   /* check if parsing suceeded */
   if (doc == NULL) {
       fprintf(stderr, "Failed to parse %s\n", filename);
   } else {
       /* check if validation suceeded */
       if (ctxt->valid == 0)
           fprintf(stderr, "Failed to validate %s\n", filename);
       /* free up the resulting document */
   /* free up the parser context */

But this would not tell me which line/element failed validation? Any other way using libxml DOM.A way where I can do element by element validation.
I hope there are APIs to do that. Pls help me with some code snippet or Documentation.

Thx in Advance,

"DISCLAIMER: This message is proprietary to Flextronics Software Systems (FSS) and is intended solely for the use of 
the individual to whom it is addressed. It may contain privileged or confidential information and should not be 
circulated or used for any purpose other than for what it is intended. If you have received this message in error, 
please notify the originator immediately. If you are not the intended recipient, you are notified that you are strictly
prohibited from using, copying, altering, or disclosing the contents of this message. FSS accepts no responsibility for 
loss or damage arising from the use of the information transmitted by this email including damage from virus."

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