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

[xml] namespace decl attributes return false for HasValue



Hi Daniel,

I have been using the xmlTextReader API in libxml2-2.5.6 on Gentoo.  I
like it very much, but I have come across the following curious corner
case: namespace declarations have NodeType=2 (i.e. attribute), return
false for HasValue, and return the namespace URI for Value.  Is this
intended behavior?  It seems a bit inconsistent to actually have a
Value but return false for HasValue.

Here is code and data files to reproduce the problem:

#include <iostream>
#include "libxml/xmlreader.h"

using namespace std;

void doit(const char* f)
{
  xmlTextReaderPtr r = xmlNewTextReaderFilename(f);
  xmlTextReaderRead(r);
  xmlTextReaderMoveToFirstAttribute(r);
  cerr << "filename                : " << f << endl;
  cerr << "are we on an attribute  : " << ((char*)((xmlTextReaderNodeType(r)==2)?"yes":"no")) << endl;
  cerr << "does it have a value    : " << ((char*)(xmlTextReaderHasValue(r)?"yes":"no")) << endl;
  cerr << "here is its value anyway: " << ((char*)xmlTextReaderValue(r)) << endl << endl;
}

int main()
{
  doit("bug1.xml");
  doit("bug2.xml");
  return 0;
}
<x:doc xmlns:x="hello"/>
<doc x="hello"/>
I suspect that this could be fixed simply by adding:

case XML_NAMESPACE_DECL:

to the switch statement in the implementation of function
xmlTextReaderHasValue in file xmlreader.c

Cheers,

-- 
Dr. Denys Duchier
Équipe Calligramme
LORIA, Nancy, FRANCE


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