471,092 Members | 1,932 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,092 software developers and data experts.

Parsing XML with Xerces-C++

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;
}
}
}
}
}
Oct 14 '06 #1
1 3212
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
Matthias Braun wrote:
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;
}
}
}
}
}
Oct 15 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Aleksandar Matijaca | last post: by
1 post views Thread by Hans Bijvoet | last post: by
3 posts views Thread by Girish | last post: by
4 posts views Thread by MBR | last post: by
8 posts views Thread by pradeepsarathy | last post: by
24 posts views Thread by Marc Dubois | last post: by
reply views Thread by jimmy Zhang | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.