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;
}
}
}
}
}
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;
}
}
}
}
}