Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Xerces C++ help in GetNodeValue(). Beginner question....

Reply
Thread Tools

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

 
 
David
Guest
Posts: n/a
 
      12-17-2003
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 xmlnssi="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>(E-Mail Removed)</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>(E-Mail Removed)</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>(E-Mail Removed)</email>
<link manager="Big.Boss"/>
</person>

<person id="three.worker">
<name><family>Worker</family> <given>Three</given></name>
<email>(E-Mail Removed)</email>
<link manager="Big.Boss"/>
</person>

<person id="four.worker">
<name><family>Worker</family> <given>Four</given></name>
<email>(E-Mail Removed)</email>
<link manager="Big.Boss"/>
</person>

<person id="five.worker">
<name><family>Worker</family> <given>Five</given></name>
<email>(E-Mail Removed)</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;


}

 
Reply With Quote
 
 
 
 
Toni Uusitalo
Guest
Posts: n/a
 
      12-17-2003
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" <(E-Mail Removed)> wrote in message
news:brqfgh$vv0$(E-Mail Removed)...
> 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 xmlnssi="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>(E-Mail Removed)</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>(E-Mail Removed)</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>(E-Mail Removed)</email>
> <link manager="Big.Boss"/>
> </person>
>
> <person id="three.worker">
> <name><family>Worker</family> <given>Three</given></name>
> <email>(E-Mail Removed)</email>
> <link manager="Big.Boss"/>
> </person>
>
> <person id="four.worker">
> <name><family>Worker</family> <given>Four</given></name>
> <email>(E-Mail Removed)</email>
> <link manager="Big.Boss"/>
> </person>
>
> <person id="five.worker">
> <name><family>Worker</family> <given>Five</given></name>
> <email>(E-Mail Removed)</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;
>
>
> }
>



 
Reply With Quote
 
 
 
 
David
Guest
Posts: n/a
 
      12-17-2003
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" <(E-Mail Removed)> wrote in message
> news:brqfgh$vv0$(E-Mail Removed)...
>> 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 xmlnssi="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>(E-Mail Removed)</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>(E-Mail Removed)</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>(E-Mail Removed)</email>
>> <link manager="Big.Boss"/>
>> </person>
>>
>> <person id="three.worker">
>> <name><family>Worker</family> <given>Three</given></name>
>> <email>(E-Mail Removed)</email>
>> <link manager="Big.Boss"/>
>> </person>
>>
>> <person id="four.worker">
>> <name><family>Worker</family> <given>Four</given></name>
>> <email>(E-Mail Removed)</email>
>> <link manager="Big.Boss"/>
>> </person>
>>
>> <person id="five.worker">
>> <name><family>Worker</family> <given>Five</given></name>
>> <email>(E-Mail Removed)</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;
>>
>>
>> }
>>


 
Reply With Quote
 
Toni Uusitalo
Guest
Posts: n/a
 
      12-17-2003
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" <(E-Mail Removed)> wrote in message
news:brqih6$1ti$(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> > news:brqfgh$vv0$(E-Mail Removed)...
> >> 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 xmlnssi="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>(E-Mail Removed)</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>(E-Mail Removed)</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>(E-Mail Removed)</email>
> >> <link manager="Big.Boss"/>
> >> </person>
> >>
> >> <person id="three.worker">
> >> <name><family>Worker</family> <given>Three</given></name>
> >> <email>(E-Mail Removed)</email>
> >> <link manager="Big.Boss"/>
> >> </person>
> >>
> >> <person id="four.worker">
> >> <name><family>Worker</family> <given>Four</given></name>
> >> <email>(E-Mail Removed)</email>
> >> <link manager="Big.Boss"/>
> >> </person>
> >>
> >> <person id="five.worker">
> >> <name><family>Worker</family> <given>Five</given></name>
> >> <email>(E-Mail Removed)</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;
> >>
> >>
> >> }
> >>

>



 
Reply With Quote
 
Toni Uusitalo
Guest
Posts: n/a
 
      12-17-2003
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" <(E-Mail Removed)> wrote in message
news:brqih6$1ti$(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> > news:brqfgh$vv0$(E-Mail Removed)...
> >> 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 xmlnssi="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>(E-Mail Removed)</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>(E-Mail Removed)</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>(E-Mail Removed)</email>
> >> <link manager="Big.Boss"/>
> >> </person>
> >>
> >> <person id="three.worker">
> >> <name><family>Worker</family> <given>Three</given></name>
> >> <email>(E-Mail Removed)</email>
> >> <link manager="Big.Boss"/>
> >> </person>
> >>
> >> <person id="four.worker">
> >> <name><family>Worker</family> <given>Four</given></name>
> >> <email>(E-Mail Removed)</email>
> >> <link manager="Big.Boss"/>
> >> </person>
> >>
> >> <person id="five.worker">
> >> <name><family>Worker</family> <given>Five</given></name>
> >> <email>(E-Mail Removed)</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;
> >>
> >>
> >> }
> >>

>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Beginner's Beginner william nelson Ruby 7 04-11-2011 11:23 PM
No Class at ALL!!! beginner/beginner question =?Utf-8?B?S3VydCBTY2hyb2VkZXI=?= ASP .Net 7 02-03-2005 02:47 PM
Upgrade of Xalan 1.2.2 and Xerces 1.4.4 to Xalan 2.6 and Xerces 2.6.2 cvissy XML 0 11-16-2004 07:06 AM
I need help with xerces-c and xalan-c, please help ------------------------------- Janice XML 0 10-12-2004 04:08 AM
Tutorial for beginner/ Tutorial voor beginner Rensjuh C++ 7 09-02-2004 12:41 AM



Advertisments