Parsing XML with Xerces-C++

M

Matthias Braun

Hilfe!

Ich habe mir eine Xerces C++ Routine geschrieben, die alle Dokumente des
XML-Trees parst. Die folgende rekursive Funktion funktioniert allerdings
nicht 100%. Wer kann helfen?

Danke, Matthias

--------------

void process_nodelist(DOMNodeList * CurrentDOMNodeList)
{
int nodeCount = CurrentDOMNodeList->getLength();
cout << endl << "Start processing nodelist with " << nodeCount << "
Elements." << endl; // real number = (nodeCount/2-1): "
for(int i=0; i<nodeCount; ++i)
{
DOMNode* currentNode = CurrentDOMNodeList->item(i);
if(currentNode->getNodeType() && currentNode->getNodeType() ==
DOMNode::ELEMENT_NODE ) // (nodeCount/2-1) loops
{
char *strNodeName =
XMLString::transcode(currentNode->getNodeName());
cout << " Name of the node is \"" << strNodeName <<
"\"" << endl;
DOMNamedNodeMap* NodeMap = currentNode->getAttributes();
for (XMLSize_t i=0; i<NodeMap->getLength(); ++i)
// Loop for the attributes
{
cout << "DEBUG: " << NodeMap->getLength() << endl;
DOMNode* currentNamedNode = NodeMap->item(i);
char *strNodeMapName =
XMLString::transcode(currentNamedNode->getNodeName());
char *strNodeMapValue =
XMLString::transcode(currentNamedNode->getNodeValue());
cout << " " << i<< ". NodeMap with name \"" <<
strNodeMapName << "\" has the value \"" << strNodeMapValue << "\"" << endl;
}
DOMNodeList * Nodelist = currentNode->getChildNodes();
if (Nodelist->getLength() > 1)
process_nodelist(Nodelist);
else
{
if ((NodeMap->getLength()==0))
{
char *str_value =
XMLString::transcode(currentNode->getTextContent());
cout << "\t\tValue of node \"" << strNodeName <<
"\" is \"" << str_value << "\"" << endl;
}
}
}
}
}
 
S

spiff

Hi Matthias!

Englisch wäre besser in einer Gruppe wie dieser. In Deutsch werden es
nicht ganz so viele verstehen ;-)

Ich nehme an es werden nicht alle Elemente angesprungen. Ist der Fehler
nicht einfach in dieser Zeile:

DOMNodeList * Nodelist = currentNode->getChildNodes();
if (Nodelist->getLength() > 1)

Wobei ich annehme, ohne DOMNodeList zu kennen, dass getLength() > 0
hier stehen müsste ansonsten werden einfach alle nodes nicht
durchsucht, die nur ein subelement haben.

Grüße spiff
http://www.spycomponents.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top