You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-users@xalan.apache.org by Kaushal Sanghavi <ka...@uclink.berkeley.edu> on 2003/07/16 03:12:59 UTC

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