It has been too long. Hopefully you have a working solution by now. But here
is the solution any way -
As David said, you gotta get to the text node of the element to get a value

                XalanNode *node = theEvaluator1->selectSingleNode(
                                        theDOMSupport,
                                        theContextNode,
                                        XalanDOMString(xpath).c_str(),
                                        (*thePrefixResolver1));
                cout<<"outputA is "<<node->getNodeValue()<<endl;  //No value
                cout<<"outputB is "<<node->getNodeName()<<endl;
                XalanNode *child = node->getFirstChild();
                // For a non-leaf node, this gives the child node or 
whitespace(if any)
                // For a leaf node, this gives the text node
                if (child!=NULL) {
                        result =        
string(convertXalanDOMString(child->getNodeValue()));
                        if (trim(result).length()>0) {
                                
                                cout<<"got it "<<trim(result)<<endl;
                        } // No need to go further. You had a leaf node
                        else {
                  
                                  while (child!=0) {
                                          if (child->getFirstChild()!=NULL) { 
//This is NULL for whitespace as
the current node
                                              cout<<"Value is 
"<<child->getFirstChild()->getNodeValue()<<endl;
                                              cout<<"output2 is 
"<<child->getNodeName()<<endl;

                                          }
                                          child = child->getNextSibling();

                                  }
                        }
                }
Note: convertXalanDOMString is my custom function - you may ignore it.
This code snippet would give you values for "/bookstore/book[1]"  and also
for "/bookstore/book[1]/author"

For your second question about year, you have to get a nodelist and then
iterate through it to get individual years. I do not know of any way for
xapth to give it directly.
Try the theEvaluator1->selectNodeList(....)    Hopefully this helps. 


Shalmi wrote:
> 
> 
> David Bertoni wrote:
>> 
>> Paul Lalonde wrote:
>>> -----BEGIN PGP SIGNED MESSAGE-----
>>> Hash: SHA1
>>> 
>>> So now I'm further confused - I tried calling XalanNode::getChildren(), 
>>> but recieved an XalanDOMException with value 9 = NOT_SUPPORTED_ERR.
>>> Clearly I'm asking for the wrong thing.  What's the right thing?
>>> 
>> 
>> This is a deliberate limitation in Xalan-C's implementation, to save 
>> memory.  Because the processor never needs to see a list of the children, 
>> only the iterative member functions are implemented.  Try the following
>> code:
>> 
>> XalanNode* child = node->getFirstChild();
>> 
>> while(child != 0)
>> {
>>      ...
>> 
>>      child = child->getNextSibling();
>> }
>> 
>> 
>> Dave
>> 
>> 
> 
> Hi,
> Consider following XML
> <?xml version="1.0" encoding="ISO-8859-1"?>
> <bookstore>
> <book category="CHILDREN">
>   <title lang="en">Harry Potter</title>
>   <author>J K. Rowling</author>
>   <year>2005</year>
>   <price>29.99</price>
> </book>
> <book category="WEB">
>   <title lang="en">Learning XML</title>
>   <author>Erik T. Ray</author>
>   <year>2003</year>
>   <price>39.95</price>
> </book>
> </bookstore>
> 
> It has four text nodes/elment(?). So if i run "/bookstore/book[1]"
> getNodeValue() on this,what should i get?
> I did traversed through the node and print it,but in this case I get null
> string. The same piece of code works for "/bookstore/book/year".
> I mean if i have to print following output what would be the generic
> approach?
> 1. For "/bookstore/book[1]"  i should get <book category="CHILDREN">
>   <title lang="en">Harry Potter</title>
>   <author>J K. Rowling</author>
>   <year>2005</year>
>   <price>29.99</price>
> </book>
> 
> 2. For "/bookstore/book/year" i should get
> 2005
> 2003
> 
> Thanks
> Shalmi
> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Getting-at-the-value-in-an-XalanNode--tp6271680p15138243.html
Sent from the Xalan - C - Users mailing list archive at Nabble.com.

Reply via email to