Read elements of a xml file??????

Hi,

What is a good way to read elements of an xml file? i did try xmllint it doesnt provide a function to output values of a tree. In the below example when i specify from Family2 I need the name of the father then the output should be DAVE. Appreciate any help provided in this regards.

Many thanks.

for instance:

One way is to use sed repeatedly as the following example shows.

 sed -n '/\<Family2\>/,/\<\/Family2\>/p' file | sed -n '/\<Father\>/,/\<\/Father\>/p' | sed -n 's/\<name=\(.*\)\/\>/\1/p'

It outputs "DAVE".

A better way is to use something like the XML extension to gawk (XMLgawk)

the above code is not working for me. and also could you please explain me in more details about XMLgawk? Thanks

Does this works?

sed -n '/Family2/{n;n;s/<name=\(.*\)\/>/\1/p}' /tmp/Input 

Thanks
Nagarajan G

thats not the solution i am looking for, actually the format could be anything like all the data in one line or multiple lines. or in any well formed format of xml. I need a generic solution to pick the element values.

Anyways, Thanks for the efforts you put in it.

I highly recommend using a XML::Parser for it

Its very easy to use and implement.

Initially for one of our tasks, without thinking about XML::Parser, I did wrote a mini XML::Parser which turned to be much complicated to maintain later.

Switch to parsers that are already available

I am not able to locate any. Could you please point me to any???