![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| just want certail elements | frenchface | Shell Programming and Scripting | 1 | 05-10-2008 06:38 PM |
| Map - printing all elements - why? | dhanamurthy | High Level Programming | 0 | 04-14-2008 10:19 AM |
| Help in extracting only certain elements in file | ahjiefreak | Shell Programming and Scripting | 1 | 12-07-2007 01:20 AM |
| seperate elements of a file | nektarios4u | Shell Programming and Scripting | 1 | 11-02-2007 10:53 AM |
| How can i read array elements dynamically in bash? | haisubbu | UNIX for Dummies Questions & Answers | 1 | 08-28-2006 11:19 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
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: Quote:
|
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
One way is to use sed repeatedly as the following example shows.
Code:
sed -n '/\<Family2\>/,/\<\/Family2\>/p' file | sed -n '/\<Father\>/,/\<\/Father\>/p' | sed -n 's/\<name=\(.*\)\/\>/\1/p' A better way is to use something like the XML extension to gawk (XMLgawk) |
|
#3
|
|||
|
|||
|
the above code is not working for me. and also could you please explain me in more details about XMLgawk? Thanks
|
|
#4
|
|||
|
|||
|
Does this works?
Code:
sed -n '/Family2/{n;n;s/<name=\(.*\)\/>/\1/p}' /tmp/Input
Nagarajan G |
|
#5
|
|||
|
|||
|
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. |
|
#6
|
|||
|
|||
|
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 |
|
#7
|
|||
|
|||
|
Quote:
|
|||
| Google The UNIX and Linux Forums |