[xml] Xpath and default attribute value



Hi,

I have a probably trivial question about XPath and test on default value - but I do not see where is my 
misunderstanding. I have following xml with embedded dtd - just note the default value "0" for attribute "st".

--------
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE test_unit [
<!ELEMENT test_unit EMPTY>
<!ATTLIST test_unit st  (ok|failed|disabled|skipped|0)     "0">
]>
<test_unit/>
--------
It seemed to me that I should find "/test_unit[ st=0]" but it does not*

What I found in specification, which seems related to this point is 
(http://www.w3.org/TR/xpath#attribute-nodes):
NOTE: It is possible for default attributes to be declared in an external DTD or an external parameter 
entity. The XML Recommendation does not require an XML processor to read an external DTD or an external 
parameter unless it is validating. A stylesheet or other facility that assumes that the XPath tree contains 
default attribute values declared in an external DTD or parameter entity may not work with some 
non-validating XML processors

my reformulation of this is: with a validating XML processor, we could assume the tree contains default 
attribute value and therefore should not "/test_unit[ st=0]" match in my example?

thank you for any answer on this point

Jean

*here is the test:

  xmlDoValidityCheckingDefaultValue=1;
  xmlInitParser();
  xmlParserCtxtPtr ctxt = xmlCreateFileParserCtxt(argv[1]);
  if (ctxt == NULL) {
    return(0);
  }
  xmlParseDocument(ctxt);
  xmlDocPtr Doc=ctxt->myDoc;
  if (!ctxt->valid) {
    fprintf(stderr,"document not valid\n");
    exit(0);
  }
  xmlXPathContextPtr ctx=xmlXPathNewContext(Doc);
  
  // check that the "st" attribute gets its value from dtd
  fprintf(stderr,"value of 'st' attribute:%s\n",xmlGetProp(xmlDocGetRootElement(Doc),(const xmlChar*)"st"));


  xmlXPathObjectPtr optval1=xmlXPathEval((const xmlChar*)"//test_unit[ st=0]",ctx);
  if (!xmlXPathCastToBoolean (optval1)) {
    fprintf(stderr,"match on //test_unit[ st=0] failed\n");
  } 

  xmlXPathObjectPtr optval2=xmlXPathEval((const xmlChar*)"//test_unit",ctx);
  if (!xmlXPathCastToBoolean (optval2)) {
    fprintf(stderr,"match on //test_unit[ st=0] failed\n");
}




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