dbTalk Databases Forums  

XmlValue navigation problem

comp.databases.berkeley-db comp.databases.berkeley-db


Discuss XmlValue navigation problem in the comp.databases.berkeley-db forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Ventura
 
Posts: n/a

Default XmlValue navigation problem - 01-12-2006 , 04:04 AM






I am trying to navigate in the XmlValue using XmlValu::getFirstChild,
Xml::getNextSibling with
no success.

For example:

<MyDoc>
<TheChildName>ABCD</TheChildName>
</MyDoc>


XmlValue val(xmlDocument);

XmlValue val.getFirstChild();

cout << val.getNodeName() << endl; // This is ok, I get the node
name

TheChildName

cout << val.getNodeValue() << endl; // This is wrong !!!

#text

I think it should be ABCD,
Is that right ?

Anybody can help me ???


Thanks in advance.
Ventura


Reply With Quote
  #2  
Old   
George Feinberg
 
Posts: n/a

Default Re: XmlValue navigation problem - 01-12-2006 , 10:31 AM






Ventura,

The XmlValue navigations methods are small wrappers around
the DOM (Document Object Model) interfaces, which can be confusing.
DOM does not specify any node value for element nodes, as you might
think (and expect), so the behavior you are seeing is correct.

In order to get the text value of the node, you need to navigate to
*its* child (text) node -- something like:
val.getFirstChild().getNodeValue()

When using these interfaces, be wary of white space in your documents,
which shows up as unexpected text nodes during
navigation. It's a good idea to test that a node is of the type
you expect before doing much with it.

Regards,

George Feinberg
Sleepycat Software


Reply With Quote
  #3  
Old   
Ventura
 
Posts: n/a

Default Re: XmlValue navigation problem - 01-13-2006 , 05:31 AM



Thanks Feinberg,
I have the code now but I still have a question. Look at the code. Why
do I have to skip a kind of hidden node "#text". Without this skip, the
code doesn't work.

XmlValue nn = cabin.getFirstChild(); // skip #text

while (!nn.isNull())
{
nn = nn.getNextSibling(); // Tag
cout << nn.getNodeName() << " = " \
<< nn.getFirstChild().getNodeValue() <<
endl;
nn = nn.getNextSibling(); // skip #text
}

Thanks in advance,
Ventura


Reply With Quote
Reply




Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.