Hi Rachita, Surely you meant to post this to the libxml [1] mailing list. This is the Xerces *Java* user mailing list. You won't find answers about libxml here.
[1] http://mail.gnome.org/mailman/listinfo/xml Michael Glavassevich XML Parser Development IBM Toronto Lab E-mail: [EMAIL PROTECTED] E-mail: [EMAIL PROTECTED] [EMAIL PROTECTED] wrote on 09/23/2006 09:38:37 AM: > 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. > Example: > <?xml version="1.0"?> > <!DOCTYPE Sample SYSTEM "d.dtd"> > Is it possible , DTD file need not be specified in XML File and > still be used for validation purpose.? > 2). I know of API xmlCtxtReadFile to get a ctxt for XML file and > then chk 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"); > > return; > > } > > /* 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 */ > > xmlFreeDoc(doc); > > } > > /* free up the parser context */ > > xmlFreeParserCtxt(ctxt); > > } > But this would not tell me which line/ element failed validation? > Any other way using libxml DOM. > I hope there are APIs to do that. > > Thx in Advance, > Rachita --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
