Re: [xml] validation & xpath



On Tue, May 19, 2009 at 01:26:04PM +0200, laurent marzu org wrote:


Hello, 

I'm trying to use XPath with libxml2 and I came accross a strange behavior
which I do not understand: 

Here a summary of the parsing of my doc and the XPath evaluation: 

I took the code sometime ago from the "xmlCreateURLParserCtxt( const char*
filename , int options )" 

 xmlParserCtxtPtr ctxt;
 xmlParserInputPtr inputStream;
 char *directory = NULL;

 ctxt->_private = this;
 ctxt->sax->serror = libxml2_gcdk_error_handler_adapter;
 ctxt->linenumbers = 1;
 ctxt->replaceEntities = 1; 

 ctxt->validate = 0; 

 inputStream = NULL;
 inputStream = xmlLoadExternalEntity(p_filename, NULL, ctxt); 

 inputPush(ctxt, inputStream);
 if ((ctxt->directory == NULL) &
 if ((ctxt->directory == NULL) & 

 ctxt->validate = 1;
 xmlParseDocument( ctxt ); 

And it seems that in this case, my XPath expressions does not gave any
result node, while when I initialize ctxt->validate to 0, It gave me the
good results. 

Is there anyone who could explain me what I'm doing wrong please ? 

  I really don't understand why you don't use xmlReadDoc directly
for parsing !
  Why XPath works without validation versus with validation might
be due to a defaulted default namespace coming from the DTD.

  But you're doing things in a very complex way and I can't see a good
reason for this. Use the existing API instead of copy/pasting stuff ...

Daniel


-- 
Daniel Veillard      | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
daniel veillard com  | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library  http://libvirt.org/



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