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

D

David

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>[email protected]</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>[email protected]</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>[email protected]</email>
<link manager="Big.Boss"/>
</person>

<person id="three.worker">
<name><family>Worker</family> <given>Three</given></name>
<email>[email protected]</email>
<link manager="Big.Boss"/>
</person>

<person id="four.worker">
<name><family>Worker</family> <given>Four</given></name>
<email>[email protected]</email>
<link manager="Big.Boss"/>
</person>

<person id="five.worker">
<name><family>Worker</family> <given>Five</given></name>
<email>[email protected]</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;


}
 
T

Toni Uusitalo

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
 
D

David

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 ???
 
T

Toni Uusitalo

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/studerende/mccash/speciale/src/sb2/Parser.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
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top