I have a problem while using XML DOM parser. When I try to print the DOM tree, I cannot print the attributes (nodeName returns "", and hasAttribute returns false). I think it is because of a bug. I have a source code here, so if anybody could tell me whether it's a bug or not :
//first method
void printTree(Poco::XML::NodeList* nodeList, unsigned int nbTabs = 0) {
unsigned long childrenCount = nodeList->length();
for(unsigned long i = 0 ; i < childrenCount ; ++i) {
Poco::XML::Node* node = nodeList->item(i);
if(node->hasChildNodes()) { // parent node
formatted(node->nodeName(), nbTabs); // print the node name
if(node->hasAttributes()) {
Poco::XML::NamedNodeMap* map = node->attributes();
// prints the attributes
unsigned long attrCount = map->length();
for(unsigned long j = 0 ; j < attrCount ; ++j) {
Poco::XML::Node* attr = map->item(j);
Poco::XML::XMLString qname = attr->nodeName(); //=> empty (bug ?) [#1]
Poco::XML::XMLString name = attr->localName(); // ok
Poco::XML::XMLString value = attr->getNodeValue();
Poco::XML::XMLString text = name + Poco::XML::XMLString(" = ") + value;
formatted(text,nbTabs,false);
}
}
printTree(node->childNodes(),nbTabs+1);
} else { // leaf
formatted(node->getNodeValue(),nbTabs);
}
}
}
// second method
void iterateThrough(Poco::XML::Node* root) {
Poco::XML::NodeIterator iterator(root,Poco::XML::NodeFilter::SHOW_ALL);
Poco::XML::Node* current = 0;
while((current = iterator.nextNode()) != 0){
formatted(current->nodeName(),1);
Poco::XML::Element* e = dynamic_cast
if(e != 0 && e->hasAttribute(Poco::XML::XMLString("brief"))) { // doesn't work because of #1
Poco::XML::XMLString attr = e->getAttribute(Poco::XML::XMLString("brief"));
}
}
}
Thanks a lot.





