473,396 Members | 1,966 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 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 3414
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: bugbear | last post by:
Subject pretty much says it all. I'd like to parse XML (duh!) using Xerces (because its fast, and reliable, and comprehensive, and supports lots of features). I'd like to conform to standards...
5
by: Aleksandar Matijaca | last post by:
Hi there, I am in some need of help. I am trying to parse using the apache sax parser a file that has vaid UTF-8 characters - I keep end up getting a sun.io.MalformedInputException error. ...
1
by: Hans Bijvoet | last post by:
Hello, I'm trying to parse a HTML document with the SAX parser from Xerces. The parser throws a fatal error when attribute values in the document are not surrounded by quotes? How can I prevent...
2
by: Cigdem | last post by:
Hello, I am trying to parse the XML files that the user selects(XML files are on anoher OS400 system called "wkdis3"). But i am permenantly getting that error: Directory0: \\wkdis3\ROOT\home...
3
by: Girish | last post by:
Hi All, I have written a component(ATL COM) that wraps Xerces C++ parser. I am firing necessary events for each of the notifications that I have handled for the Content and Error handler. The...
4
by: MBR | last post by:
Help! Does anybody know a simple example how to use xerces (http://xml.apache.org) with C++ to parse a simple xml file, go from node to node and read the data in the nodes? Thanks, Matthias
8
by: pradeepsarathy | last post by:
Hi all, Does the SAX parser has eventhandlers for parsing xml schema. Can we parse the xml schema the same way as we parse the xml document using SAX Parser. Thanks in advance. -pradeep
24
by: Marc Dubois | last post by:
hi, is it possible to parse an XML file in C so that i can fulfill these requirements : 1) replace all "<" and ">" signs inside the body of tag by a space, e.g. : Example 1: <fooblabla < bla...
0
by: jimmy Zhang | last post by:
VTD-XML (http://vtd-xml.sf.net) may also be interesting to you "Martin Honnen" <mahotrash@yahoo.dewrote in message news:47cd3ee6$0$25510$9b4e6d93@newsspool1.arcor-online.net...
1
by: Sidhartha | last post by:
Hi, I am facing a problem while parsing local language characters using sax parser. We use DOM to parse and SAX to read the source. But when our application parses strings with local language...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.