472,784 Members | 844 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Xerces C++ help in GetNodeValue(). Beginner question....

Hello ,
I'm trying to parse an XML document a get spicific tags such as email in the
code below. I'm using xerces 2.4. However I don't manage to get the value
for the email. Can anybody help.

thanks in advance,

david

---------------
This the output of the piece of code below

Index:0 Value:0
Index:1 Value:0
Index:2 Value:0
Index:3 Value:0
Index:4 Value:0
Index:5 Value:0

-----------------
This the XML file:

<?xml version="1.0" encoding="UTF-8"?>
<?proc-inst-1 'foo' ?>
<personnel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation='personal.xsd'>

<person id="Big.Boss">
<name xml:base="foo/bar"><family xml:base="bar/bar">Boss</family>
<given xml:base="car/bar">Big</given><?proc-inst-2 'foobar' ?></name>
<email>ch***@foo.com</email>
<link subordinates="one.worker two.worker three.worker four.worker
five.worker"/>
</person>

<person id="one.worker" xml:base="/auto/bar">
<name xml:base="/car/foo/"><family xml:base="bar/bar">Worker</family>
<given>One</given></name>
<email>on*@foo.com</email>
<link manager="Big.Boss"/>
</person>

<person id="two.worker" xml:base="http://www.example.com/car/car">
<name xml:base="/bar/foo/"><family xml:base="foo/bar">Worker</family>
<given>Two</given></name>
<email>tw*@foo.com</email>
<link manager="Big.Boss"/>
</person>

<person id="three.worker">
<name><family>Worker</family> <given>Three</given></name>
<email>th***@foo.com</email>
<link manager="Big.Boss"/>
</person>

<person id="four.worker">
<name><family>Worker</family> <given>Four</given></name>
<email>fo**@foo.com</email>
<link manager="Big.Boss"/>
</person>

<person id="five.worker">
<name><family>Worker</family> <given>Five</given></name>
<email>fi**@foo.com</email>
<link manager="Big.Boss"/>
</person>

</personnel>
--------------------------
This is a piece of the code

Main.cpp
........
DOMDocument *doc = parser->getDocument();
DOMElement *root = doc->getDocumentElement();
DOMNode *node;
XMLCh* tmpstr;
int len;
int i;

XMLString::transcode("email", tmpstr ,50);

DOMNodeList *list = doc->getElementsByTagName(tmpstr);
len = list->getLength();

for (i=0; i< len ;i++)
{
//Returns DOMnode object
node = list->item(i);

const XMLCh* n = node->getNodeValue();
cout << "Index:" << i << " Value:" << n <<endl;

}
delete parser;
delete errHandler;

XMLPlatformUtils::Terminate();
return 0;
}

Jul 20 '05 #1
4 11401
I think you must get the value of text node (remember "in DOM everything is
a node", thus text is also node) which in your case is firstChild of your
email element i.e.
something like:
node.firstChild.NodeValue
(inside your loop)

with respect,
Toni Uusitalo
"David" <no****@home.com> wrote in message
news:br**********@newshispeed.ch...
Hello ,
I'm trying to parse an XML document a get spicific tags such as email in the code below. I'm using xerces 2.4. However I don't manage to get the value
for the email. Can anybody help.

thanks in advance,

david

---------------
This the output of the piece of code below

Index:0 Value:0
Index:1 Value:0
Index:2 Value:0
Index:3 Value:0
Index:4 Value:0
Index:5 Value:0

-----------------
This the XML file:

<?xml version="1.0" encoding="UTF-8"?>
<?proc-inst-1 'foo' ?>
<personnel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation='personal.xsd'>

<person id="Big.Boss">
<name xml:base="foo/bar"><family xml:base="bar/bar">Boss</family>
<given xml:base="car/bar">Big</given><?proc-inst-2 'foobar' ?></name>
<email>ch***@foo.com</email>
<link subordinates="one.worker two.worker three.worker four.worker
five.worker"/>
</person>

<person id="one.worker" xml:base="/auto/bar">
<name xml:base="/car/foo/"><family xml:base="bar/bar">Worker</family>
<given>One</given></name>
<email>on*@foo.com</email>
<link manager="Big.Boss"/>
</person>

<person id="two.worker" xml:base="http://www.example.com/car/car">
<name xml:base="/bar/foo/"><family xml:base="foo/bar">Worker</family>
<given>Two</given></name>
<email>tw*@foo.com</email>
<link manager="Big.Boss"/>
</person>

<person id="three.worker">
<name><family>Worker</family> <given>Three</given></name>
<email>th***@foo.com</email>
<link manager="Big.Boss"/>
</person>

<person id="four.worker">
<name><family>Worker</family> <given>Four</given></name>
<email>fo**@foo.com</email>
<link manager="Big.Boss"/>
</person>

<person id="five.worker">
<name><family>Worker</family> <given>Five</given></name>
<email>fi**@foo.com</email>
<link manager="Big.Boss"/>
</person>

</personnel>
--------------------------
This is a piece of the code

Main.cpp
.......
DOMDocument *doc = parser->getDocument();
DOMElement *root = doc->getDocumentElement();
DOMNode *node;
XMLCh* tmpstr;
int len;
int i;

XMLString::transcode("email", tmpstr ,50);

DOMNodeList *list = doc->getElementsByTagName(tmpstr);
len = list->getLength();

for (i=0; i< len ;i++)
{
//Returns DOMnode object
node = list->item(i);

const XMLCh* n = node->getNodeValue();
cout << "Index:" << i << " Value:" << n <<endl;

}
delete parser;
delete errHandler;

XMLPlatformUtils::Terminate();
return 0;
}

Jul 20 '05 #2
I have modified the code as follows but still doesn't work. ANy idea ?

cout << "LIST:" << len <<endl;
for (i=0; i< len ;i++)
{
//Returns DOMnode object
node = list->item(i);
const XMLCh* test = node->getFirstChild()->getNodeValue();
cout << "Index:" << i << " Value:" << test <<" Type:" <<endl;

}

I get:
Index:0 Value:0x806f6f8
Index:1 Value:0x8070140
Index:2 Value:0x8070b28
Index:3 Value:0x8071290
Index:4 Value:0x80719f8
Index:5 Value:0x8072158
ANy idea ???
Toni Uusitalo wrote:
I think you must get the value of text node (remember "in DOM everything
is a node", thus text is also node) which in your case is firstChild of
your email element i.e.
something like:
node.firstChild.NodeValue
(inside your loop)

with respect,
Toni Uusitalo
"David" <no****@home.com> wrote in message
news:br**********@newshispeed.ch...
Hello ,
I'm trying to parse an XML document a get spicific tags such as email in

the
code below. I'm using xerces 2.4. However I don't manage to get the value
for the email. Can anybody help.

thanks in advance,

david

---------------
This the output of the piece of code below

Index:0 Value:0
Index:1 Value:0
Index:2 Value:0
Index:3 Value:0
Index:4 Value:0
Index:5 Value:0

-----------------
This the XML file:

<?xml version="1.0" encoding="UTF-8"?>
<?proc-inst-1 'foo' ?>
<personnel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation='personal.xsd'>

<person id="Big.Boss">
<name xml:base="foo/bar"><family xml:base="bar/bar">Boss</family>
<given xml:base="car/bar">Big</given><?proc-inst-2 'foobar' ?></name>
<email>ch***@foo.com</email>
<link subordinates="one.worker two.worker three.worker four.worker
five.worker"/>
</person>

<person id="one.worker" xml:base="/auto/bar">
<name xml:base="/car/foo/"><family xml:base="bar/bar">Worker</family>
<given>One</given></name>
<email>on*@foo.com</email>
<link manager="Big.Boss"/>
</person>

<person id="two.worker" xml:base="http://www.example.com/car/car">
<name xml:base="/bar/foo/"><family xml:base="foo/bar">Worker</family>
<given>Two</given></name>
<email>tw*@foo.com</email>
<link manager="Big.Boss"/>
</person>

<person id="three.worker">
<name><family>Worker</family> <given>Three</given></name>
<email>th***@foo.com</email>
<link manager="Big.Boss"/>
</person>

<person id="four.worker">
<name><family>Worker</family> <given>Four</given></name>
<email>fo**@foo.com</email>
<link manager="Big.Boss"/>
</person>

<person id="five.worker">
<name><family>Worker</family> <given>Five</given></name>
<email>fi**@foo.com</email>
<link manager="Big.Boss"/>
</person>

</personnel>
--------------------------
This is a piece of the code

Main.cpp
.......
DOMDocument *doc = parser->getDocument();
DOMElement *root = doc->getDocumentElement();
DOMNode *node;
XMLCh* tmpstr;
int len;
int i;

XMLString::transcode("email", tmpstr ,50);

DOMNodeList *list = doc->getElementsByTagName(tmpstr);
len = list->getLength();

for (i=0; i< len ;i++)
{
//Returns DOMnode object
node = list->item(i);

const XMLCh* n = node->getNodeValue();
cout << "Index:" << i << " Value:" << n <<endl;

}
delete parser;
delete errHandler;

XMLPlatformUtils::Terminate();
return 0;
}


Jul 20 '05 #3
Hmm. at least it seems like test is now pointing to some string/somewhere
(DOMstring?), we're getting closer. ;-)

check last two functions in this:

http://www.diku.dk/hjemmesider/stude...arser.cpp.html

they will help you to get textNodes from mixed content, should be useful.
You might have to transcode your DOMstring nodeValue to appropriate C++
type,
I don't know anything about Xerces-C must admit nor I don't use C++ much.
Maybe there's some example demonstrating this in Xerces docs?

with respect,
Toni Uusitalo
"David" <no****@home.com> wrote in message
news:br**********@newshispeed.ch...
I have modified the code as follows but still doesn't work. ANy idea ?

cout << "LIST:" << len <<endl;
for (i=0; i< len ;i++)
{
//Returns DOMnode object
node = list->item(i);
const XMLCh* test = node->getFirstChild()->getNodeValue();
cout << "Index:" << i << " Value:" << test <<" Type:" <<endl;

}

I get:
Index:0 Value:0x806f6f8
Index:1 Value:0x8070140
Index:2 Value:0x8070b28
Index:3 Value:0x8071290
Index:4 Value:0x80719f8
Index:5 Value:0x8072158
ANy idea ???
Toni Uusitalo wrote:
I think you must get the value of text node (remember "in DOM everything
is a node", thus text is also node) which in your case is firstChild of
your email element i.e.
something like:
node.firstChild.NodeValue
(inside your loop)

with respect,
Toni Uusitalo
"David" <no****@home.com> wrote in message
news:br**********@newshispeed.ch...
Hello ,
I'm trying to parse an XML document a get spicific tags such as email in
the
code below. I'm using xerces 2.4. However I don't manage to get the

value for the email. Can anybody help.

thanks in advance,

david

---------------
This the output of the piece of code below

Index:0 Value:0
Index:1 Value:0
Index:2 Value:0
Index:3 Value:0
Index:4 Value:0
Index:5 Value:0

-----------------
This the XML file:

<?xml version="1.0" encoding="UTF-8"?>
<?proc-inst-1 'foo' ?>
<personnel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation='personal.xsd'>

<person id="Big.Boss">
<name xml:base="foo/bar"><family xml:base="bar/bar">Boss</family>
<given xml:base="car/bar">Big</given><?proc-inst-2 'foobar' ?></name>
<email>ch***@foo.com</email>
<link subordinates="one.worker two.worker three.worker four.worker
five.worker"/>
</person>

<person id="one.worker" xml:base="/auto/bar">
<name xml:base="/car/foo/"><family xml:base="bar/bar">Worker</family> <given>One</given></name>
<email>on*@foo.com</email>
<link manager="Big.Boss"/>
</person>

<person id="two.worker" xml:base="http://www.example.com/car/car">
<name xml:base="/bar/foo/"><family xml:base="foo/bar">Worker</family> <given>Two</given></name>
<email>tw*@foo.com</email>
<link manager="Big.Boss"/>
</person>

<person id="three.worker">
<name><family>Worker</family> <given>Three</given></name>
<email>th***@foo.com</email>
<link manager="Big.Boss"/>
</person>

<person id="four.worker">
<name><family>Worker</family> <given>Four</given></name>
<email>fo**@foo.com</email>
<link manager="Big.Boss"/>
</person>

<person id="five.worker">
<name><family>Worker</family> <given>Five</given></name>
<email>fi**@foo.com</email>
<link manager="Big.Boss"/>
</person>

</personnel>
--------------------------
This is a piece of the code

Main.cpp
.......
DOMDocument *doc = parser->getDocument();
DOMElement *root = doc->getDocumentElement();
DOMNode *node;
XMLCh* tmpstr;
int len;
int i;

XMLString::transcode("email", tmpstr ,50);

DOMNodeList *list = doc->getElementsByTagName(tmpstr);
len = list->getLength();

for (i=0; i< len ;i++)
{
//Returns DOMnode object
node = list->item(i);

const XMLCh* n = node->getNodeValue();
cout << "Index:" << i << " Value:" << n <<endl;

}
delete parser;
delete errHandler;

XMLPlatformUtils::Terminate();
return 0;
}

Jul 20 '05 #4
I browsed Xerces-C docs abit
(http://xml.apache.org/xerces-c/Apach...BindingL3.html) and noticed that
there's
function getTextContent(). This is DOM 3 feature I believe, it doesn't
hurt to get used to the idea that "everything is a node" though - that's
the way DOM works.

"David" <no****@home.com> wrote in message
news:br**********@newshispeed.ch...
I have modified the code as follows but still doesn't work. ANy idea ?

cout << "LIST:" << len <<endl;
for (i=0; i< len ;i++)
{
//Returns DOMnode object
node = list->item(i);
const XMLCh* test = node->getFirstChild()->getNodeValue();
cout << "Index:" << i << " Value:" << test <<" Type:" <<endl;

}

I get:
Index:0 Value:0x806f6f8
Index:1 Value:0x8070140
Index:2 Value:0x8070b28
Index:3 Value:0x8071290
Index:4 Value:0x80719f8
Index:5 Value:0x8072158
ANy idea ???
Toni Uusitalo wrote:
I think you must get the value of text node (remember "in DOM everything
is a node", thus text is also node) which in your case is firstChild of
your email element i.e.
something like:
node.firstChild.NodeValue
(inside your loop)

with respect,
Toni Uusitalo
"David" <no****@home.com> wrote in message
news:br**********@newshispeed.ch...
Hello ,
I'm trying to parse an XML document a get spicific tags such as email in
the
code below. I'm using xerces 2.4. However I don't manage to get the

value for the email. Can anybody help.

thanks in advance,

david

---------------
This the output of the piece of code below

Index:0 Value:0
Index:1 Value:0
Index:2 Value:0
Index:3 Value:0
Index:4 Value:0
Index:5 Value:0

-----------------
This the XML file:

<?xml version="1.0" encoding="UTF-8"?>
<?proc-inst-1 'foo' ?>
<personnel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation='personal.xsd'>

<person id="Big.Boss">
<name xml:base="foo/bar"><family xml:base="bar/bar">Boss</family>
<given xml:base="car/bar">Big</given><?proc-inst-2 'foobar' ?></name>
<email>ch***@foo.com</email>
<link subordinates="one.worker two.worker three.worker four.worker
five.worker"/>
</person>

<person id="one.worker" xml:base="/auto/bar">
<name xml:base="/car/foo/"><family xml:base="bar/bar">Worker</family> <given>One</given></name>
<email>on*@foo.com</email>
<link manager="Big.Boss"/>
</person>

<person id="two.worker" xml:base="http://www.example.com/car/car">
<name xml:base="/bar/foo/"><family xml:base="foo/bar">Worker</family> <given>Two</given></name>
<email>tw*@foo.com</email>
<link manager="Big.Boss"/>
</person>

<person id="three.worker">
<name><family>Worker</family> <given>Three</given></name>
<email>th***@foo.com</email>
<link manager="Big.Boss"/>
</person>

<person id="four.worker">
<name><family>Worker</family> <given>Four</given></name>
<email>fo**@foo.com</email>
<link manager="Big.Boss"/>
</person>

<person id="five.worker">
<name><family>Worker</family> <given>Five</given></name>
<email>fi**@foo.com</email>
<link manager="Big.Boss"/>
</person>

</personnel>
--------------------------
This is a piece of the code

Main.cpp
.......
DOMDocument *doc = parser->getDocument();
DOMElement *root = doc->getDocumentElement();
DOMNode *node;
XMLCh* tmpstr;
int len;
int i;

XMLString::transcode("email", tmpstr ,50);

DOMNodeList *list = doc->getElementsByTagName(tmpstr);
len = list->getLength();

for (i=0; i< len ;i++)
{
//Returns DOMnode object
node = list->item(i);

const XMLCh* n = node->getNodeValue();
cout << "Index:" << i << " Value:" << n <<endl;

}
delete parser;
delete errHandler;

XMLPlatformUtils::Terminate();
return 0;
}

Jul 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Bekkali Hicham | last post by:
hi, i have downloaded the latest version 2.4 of Xerces, and unziped it, i end up with a diectory hierarchy like this c:\xerces-2_4_0\XercesImpl.jar c:\xerces-2_4_0\XercesSamples.jar...
0
by: Ralf Höppner | last post by:
I'm using xerces-c++ 2.4.0 and am testing some functions of it. How can I print the name or the value of a node to console ? I tried: const XMLCh* test=node->getNodeValue(); but it seems to...
0
by: Waseem | last post by:
Hi I have looked and tried everything and i still cant sort this out i have no idea why this wont work I am using Xerces Perl on Windows and Debian to try this and it wont work on both of...
2
by: MBR | last post by:
Problem with xerces and C++ Hi, I try the sample from the xerces homepage http://xml.apache.org/xerces-c/program-dom.html, take the iterator and step through the tree: for (DOMNode*...
2
by: MBR | last post by:
Help! I am using xerces with C++ and want to read the following simple file: <?xml version="1.0"?> <pets> <pet> <name>Tilly</name> <age>14</age> <type>cat</type>
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
3
by: Raphael Tagliani | last post by:
(english version below) Bonjour! Je travaille sur un gros projet java, qui parse beaucoup de fichiers xml au lancement d'un serveur. Nous avons un problème de concurrence qu lancement. En...
1
by: Matthias Braun | last post by:
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,...
3
by: landoao | last post by:
I have found as following function. It must returns outtext but I don't know about C++ and Xerces-C++ library any more. who can execute this function on C++ and returm me input XML file and Output...
0
by: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.