I don't use XMLish files, but I ran across this utility. if you have access to xml_grep, this task can be straight-forward. I modified your data file to put it into proper format and to differentiate between data1 and data2, then ran this script:
#!/usr/bin/env bash
# @(#) s1 Demonstrate extract data from XML file, xml_grep.
# Reference for XPath: http://en.wikipedia.org/wiki/XPath_1.0
# xml_grep: http://xmltwig.com/tool/
echo
set +o nounset
LC_ALL=C ; LANG=C ; export LC_ALL LANG
echo "Environment: LC_ALL = $LC_ALL, LANG = $LANG"
echo "(Versions displayed with local utility \"version\")"
version >/dev/null 2>&1 && version "=o" $(_eat $0 $1) xml_grep
set -o nounset
echo
FILE=${1-data1}
echo " Data file $FILE:"
cat $FILE
echo
echo " Results:"
xml_grep --text_only --cond '*[@name="data1"]/String' $FILE
exit 0
producing:
% ./s1
Environment: LC_ALL = C, LANG = C
(Versions displayed with local utility "version")
OS, ker|rel, machine: Linux, 2.6.26-2-amd64, x86_64
Distribution : Debian GNU/Linux 5.0
GNU bash 3.2.39
/usr/bin/xml_grep version 0.7
Data file data1:
<project>
<key name="data1">
<String>abcdef</String>
<String>abcdef1</String>
<String>abcdef2</String>
</key>
<key name="data2">
<String>abcdefg</String>
<String>abcdefg1</String>
<String>abcdefg2</String>
<String>abcdefg3</String>
</key>
</project>
Results:
abcdef
abcdef1
abcdef2
The xml_grep perl script was in the Debian repository for me. The site URL is listed in the script above. Good luck ... cheers, drl
C:\Perl>sed -e 's/\(<[^<][^<]*>\)//g' dump.xml
The filename, directory name, or volume label syntax is incorrect.
The output is the same for all the sed commands.
I tried the awk code and i got this error
String found where operator expected at awk.pl line 9, near "}'"
(Might be a runaway multi-line '' string starting on line 1)
(Missing semicolon on previous line?)
syntax error at awk.pl line 9, near "}'"
Execution of awk.pl aborted due to compilation errors.
line 9 is the last line and i gave my filename there i.e., }' dump.xml. This is my 9th line.