Re: [xml] xmllint and namespaces



Hi Daniel,

Thanks for your help, but I am not over with the issue. I prefered not to pollute my files and so I got rid of the namespace prefix (as I will not mix my xml-data with other). So

<giml:giml xmlns:giml="http://gitk.sourceforge.net/";>
   <giml:context/>
</giml:giml>

has been changed to

<giml xmlns="http://gitk.sourceforge.net/";>
   <context/>
</giml>

I keep the default namespace. No all of my xpath queries are broken. Sorry that I post a code fragment ...

  if((ctxt=xmlXPathNewContext(elements->doc))) {
    if(root_node) ctxt->node=root_node;
    else ctxt->node=xmlDocGetRootElement(elements->doc);
    //ctxt->namespaces=g_new(xmlNsPtr,1);
    //ctxt->namespaces[0]=elements->ns;
    //ctxt->nsNr=1;
    ctxt->namespaces=NULL;
    ctxt->nsNr=0;
    gitk_log("  before xmlXPathCompiledEval()");
    result=xmlXPathCompiledEval(xpath_expression,ctxt);
g_free(ctxt->namespaces);// @todo does xmlXPathFreeContext does that for me too ?
    xmlXPathFreeContext(ctxt);
  }
  else { gitk_err("failed to get xpath context"); }

When I execute this I get :
[gitktools.c:101] :   before xmlXPathCompiledEval()
[gitkerrors.c:74] : libxml-error: Error Undefined namespace prefix
[gitkerrors.c:74] : libxml-error: xmlXPathCompiledEval: evaluation failed

Both versions (one is disabled with comments) have the problem. Can I use Xpath withourt namespace (I think so) and if yes how ?

Stefan

Hi hi,

I am sure this has been aksed bevor but wasn't succesful in the mail-archive.
I've just tried to use

xmllint --noout --valid test.xml

on test.xml :

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE giml SYSTEM "/opt/gitk/share/gitk/giml.dtd">
<giml:giml xmlns:giml="http://gitk.sourceforge.net/";>
  <giml:context/>
</giml:giml>

a fragment of the dtd :

<!ELEMENT giml (context+)>
<!ELEMENT context (#PCDATA)>

and get the following output:

test.xml:6: validity error: Element giml content doesn't follow the DTD
Expecting (context)+, got (giml:context )
</giml:giml>

this looks to me as libxml2 would like me to put the name space into the dtd, which I don't belive is the right thing to do.


Well it is ... Validation happens before namespace recognition.
You must use the QName in the DTD as seens in the instance:

<!DOCTYPE giml:giml SYSTEM "/opt/gitk/share/gitk/giml.dtd">
<giml:giml xmlns:giml="http://gitk.sourceforge.net/";>
    <giml:context/>
</giml:giml>

and
<!ELEMENT giml:glim (glim:context+)>
<!ELEMENT giml:context (#PCDATA)>

and don't forgot to add xmlns:giml as part of <!ATTLIST giml:glim

Or use the default namespace <giml xmlns="http://gitk.sourceforge.net/";>
      <context/>
   </giml>

and keep your DTD as-is

  And please make sure you use the latests versions of libxml2

Daniel




--
      \|/            Stefan Kost
     <@ @>           private            business
+-oOO-(_)-OOo------------------------------------------------------ - - -  -   -
|       __  Address  Simildenstr. 5     HTWK Leipzig, Fb IMN, Postfach 300066
|      ///           04277 Leipzig      04277 Leipzig
| __  ///            Germany            Germany
| \\\///    Phone    +49341 2253538     +49341 30766101
|  \__/     EMail    st_kost gmx net    kost imn htwk-leipzig de
|           WWW      www.sonicpulse.de  www.imn.htwk-leipzig.de/~kost/about.html
===-=-=--=---=---------------------------------- - - -  -    -




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