Parsing XML with Xerces-C++

Matthias Braun

Usenet Archive
Joined
Oct 14, 2006
Messages
12
Reaction score
0
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 } } } }
 

Matthias Braun

Usenet Archive
Joined
Oct 14, 2006
Messages
12
Reaction score
0
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
 

Matthias Braun

Usenet Archive
Joined
Oct 14, 2006
Messages
12
Reaction score
0
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
548,051
Messages
3,104,251
Members
248,135
Latest member
tobystanx

Latest Threads

Top