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