Hi all,

Thank you all very much for your help. As Erik suggested below, I can get the 
values stored in between an element's open (<>) and close (</>) tags, using 
the text() method.
To be noted, is that when using this on the command line, I need to call it 
using " ", for eg.:
bash-2.03$ SerializeNodeSet SerializeNodeSet/foo.xml / "/doc/name/foo/text()"
(this is because the shell complains otherwise, since it interprets the 
parentheses in a different way).
Thanks so much for that helpful bit of info!

However, I still am facing the issue about getting all the values in an 
attribute, as below:

I need:
bash-2.03$ mySerializeNodeSet SerializeNodeSet/foo.xml / /doc/name/@first
TO RETURN:
David David Donald Emily .... Stephen

INSTEAD, I get:
bash-2.03$ mySerializeNodeSet SerializeNodeSet/foo.xml / /doc/name/@first

Warning: An attribute or namespace node was selected. Attribute and namespace 
nodes cannot be serialized.

Warning: An attribute or namespace node was selected. Attribute and namespace 
nodes cannot be serialized.

Warning: An attribute or namespace node was selected. Attribute and namespace 
nodes cannot be serialized.

Warning: An attribute or namespace node was selected. Attribute and namespace 
nodes cannot be serialized.

Warning: An attribute or namespace node was selected. Attribute and namespace 
nodes cannot be serialized.

Warning: An attribute or namespace node was selected. Attribute and namespace 
nodes cannot be serialized.

Warning: An attribute or namespace node was selected. Attribute and namespace 
nodes cannot be serialized.

Warning: An attribute or namespace node was selected. Attribute and namespace 
nodes cannot be serialized.

Warning: An attribute or namespace node was selected. Attribute and namespace 
nodes cannot be serialized.

Warning: An attribute or namespace node was selected. Attribute and namespace 
nodes cannot be serialized.

(this warning is printed 10 times for the 10 names that are in the XML)..


Again, I'm just trying to play around with the SerializeNodeSet file in the 
samples directory that is distributed with Xalan-c++.
So, the loop that iterates over the nodeRefList reads as:
for (NodeRefList::size_type i = 0; i < theLength; ++i)
{
const XalanNode* const theNode = theResult.item(i);
assert(theNode != 0);

const XalanNode::NodeType theNodeType =
theNode->getNodeType();

if (theNodeType == XalanNode::DOCUMENT_NODE)
{
cerr << endl
<< "Warning: The root was selected. The root cannot be serialized."
<< endl;
}
else if (theNodeType == XalanNode::ATTRIBUTE_NODE)
{
cerr << endl
<< "Warning: An attribute or namespace node was selected. Attribute and 
namespace nodes cannot be serialized."
<< endl;
}
else
{
cout << "traversing subtree...resStr is: " << resStr << endl;
theWalker.traverseSubtree(theNode);
}
}

- I'm not sure where I can concatenate, as Erik suggests; it seems as though 
the concatenation (as seen in the output) takes place in the 'traverseSubtree' 
method that is defined in the FormatterTreeWalker class.

- Also, I'm presuming you mean NodeRefList when you mention 'nodeset' , since 
the XPathEvaluator class only has methods that return NodeRefList's.

- Am I missing something Erik mentioned/implied?

- Am I supposed to do something different to be able to get all the first 
Names of the people in the example xml given below?

Thanks a lot for reading this, I'm hoping this is not too much of a bother for 
the xalan pro's on this list! :)

 - Kaushal



>===== Original Message From <[EMAIL PROTECTED]> =====
>I won't write the C++ code for you but here are the XPath expressions to
>select the nodes you are interested in.
>
>1: /doc/name/foo/text()
>2: /doc/name/@first
>
>Both these expressions return a nodeset. Just iterate over the nodeset
>and concatenate the nodevalue (and perhaps inserting a newline in
>between). It should get you what you are after.
>
>Regards
>Erik Rydgren
>Mandarin IT
>Sweden
>
>> -----Original Message-----
>> From: Kaushal Sanghavi [mailto:[EMAIL PROTECTED]
>> Sent: den 17 juli 2003 04:00
>> To: xalan-c-users
>> Subject: getting a set of attribute values from xml using c
>>
>> This is what I'm trying:
>>
>> I'm just toying with the SerializeNodeSet sample code, and using the
>> foo.xml
>> as data. I've changed foo.xml to look like this:
>>
>> <?xml version="1.0"?>
>> <doc>
>>   <name first="David" last="Marston">Mr. Marston
>>    <foo> 123  </foo>
>>     <foo> 358  </foo>
>>      <foo> 526  </foo>
>>   </name>
>>   <name first="David" last="Bertoni">Mr. Bertoni
>>    <foo> 1238  </foo>
>>     <foo> 3585  </foo>
>>      <foo> 5266  </foo>
>>      <foo> sjk </foo>
>>   </name>
>>
>>   <name first="Donald" last="Leslie">Mr. Leslie</name>
>>   <name first="Emily" last="Farmer">Ms. Farmer</name>
>>   <name first="Myriam" last="Midy">Ms. Midy</name>
>>   <name first="Paul" last="Dick">Mr. Dick</name>
>>   <name first="Scott" last="Boag">Mr. Boag</name>
>>   <name first="Shane" last="Curcuru">Mr. Curcuru</name>
>>   <name first="Joseph" last="Kesselman">Mr. Kesselman</name>
>>   <name first="Stephen" last="Auriemma">Mr. Auriemma</name>
>> </doc>
>>
>> Two questions:
>> 1. I'm trying to get only the value enclosed in the foo element.
>> (for eg., 123 at the above). Instead, what I'm getting is the
>following:
>> bash-2.03$ SerializeNodeSet SerializeNodeSet/foo.xml / //foo
>> <foo> 123  </foo><foo> 358  </foo><foo> 526  </foo><foo> 1238
></foo><foo>
>> 3585  </foo><foo> 5266  </foo><foo> sjk </foo>
>>
>> 2. I'm trying to get a list of only the first names, i.e. the value
>stored
>> in
>> the attribute "name/@first" . How can I do that.
>>
>>  - Also, how do I insert a \n or a space, or some de-limiting
>character
>> between the results, so I don't get everything as one continous
>string, as
>> above?
>>
>> I'm hoping these will be easy for all the xalan gurus out there! :)
>>
>> Thanks,
>> Kaushal

Reply via email to