Parsing XML with Xerces-C++

M

Matthias Braun

All,

I reworked my code (thanks to spiff) to go through a document to parse
all elements/attributes. Now it is working (almost) fine, but still
there are some bugs: if the XML document is containnig somehow

<mff><ts>20060804162417+0200</ts></mff>

The output is
Name of the node is "mff"
Value of the node is "20060804162417+0200"
Name of the node is "ts"
Value of the node is "20060804162417+0200"

Also for this kind of XML
<mt>NumDrop.Update</mt>

the code is working because NodeMap->getLength() is equal 1

Thanks,

Matthias
__________________________________

void process_domnodelist(DOMNodeList * CurrentDOMNodeList)
{
int nodeCount = CurrentDOMNodeList->getLength();
for(int i=0; i<nodeCount; ++i)
{
DOMNode* currentNode = CurrentDOMNodeList->item(i);
if(currentNode->getNodeType() && currentNode->getNodeType() ==
DOMNode::ELEMENT_NODE )
{
cout << " Name of the node is \"" <<
XMLString::transcode(currentNode->getNodeName()) << "\"" << endl;
DOMNamedNodeMap* NodeMap = currentNode->getAttributes();
for (XMLSize_t i=0; i<NodeMap->getLength(); ++i)

{
DOMNode* currentNamedNode = NodeMap->item(i);
cout << " " << i << ". NodeMap with name \"" <<
XMLString::transcode(currentNamedNode->getNodeName()) << "\" has the
value \"" << XMLString::transcode(currentNamedNode->getNodeValue()) <<
"\"" << endl;
}
DOMNodeList * Nodelist = currentNode->getChildNodes();
if (NodeMap->getLength()== 0 && Nodelist->getLength() == 1)
cout << " Value of the node is \"" <<
XMLString::transcode(currentNode->getTextContent()) << "\"" << endl;
if (Nodelist->getLength() > 0)
{
process_domnodelist(Nodelist); // recursive loop
}
}
}
}
 
M

Matthias Braun

Joe,

I tried "if (currentNode->getNodeName() != NULL)" but without success.
Could you point out more specific which code fragment you mean?

What I don't understand - why is "NodeMap->getLength()" not working
properly?

Thanks,

Matthias
 
M

Matthias Braun

Joe,

I tried "if (currentNode->getNodeName() != NULL)" but without success.
Could you point out more specific which code fragment you mean?

What I don't understand - why is "NodeMap->getLength()" not working
properly?

Thanks,

Matthias
 

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

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,165
Latest member
JavierBrak
Top