468,535 Members | 1,681 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,535 developers. It's quick & easy.

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 10760
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Bekkali Hicham | last post: by
reply views Thread by Ralf Höppner | last post: by
reply views Thread by Waseem | last post: by
2 posts views Thread by MBR | last post: by
2 posts views Thread by MBR | last post: by
4 posts views Thread by MBR | last post: by
3 posts views Thread by Raphael Tagliani | last post: by
1 post views Thread by Matthias Braun | last post: by
3 posts views Thread by landoao | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.