Parse String in XML file

Hello All,

I am new to this and I need to parse an XML file.

Here's the XML Input File:
<Report version="1.2">
<summary fatals="0" testcases="1" expected_fails="0" unexpected_passes="0" warnings="9" tests="21" errors="0" fails="1" passes="20" />
<testresult line="../shared/scripts/addElement.js:573" message="Add Network Element [ Tampines ] successfully created" result="PASS" time="2007-12-13T16:23:47" />
</Report version>

The expected output should be:
Report

summary fatals=0 testcases=1 expected_fails=0 unexpected_passes=0 warnings=9 tests=21 errors=0 fails=1 passes=20

Add Network Element [ Tampines ] successfully created -- PASS

Can you help me with the script to have the output?

Thanks in advance.
racbern

take a look at this little script I wrote to parse your basic sqlplus login string

input should be in the format user/pass@inst

#!/usr/bin/ksh

######################
## login string parser
######################

echo "Input your login string:"
read string

echo "\nYou entered: $string"
export SRC_USERPASS=${string%%@*}
export SRC_USER=${SRC_USERPASS%%/*}
export SRC_INST=${string##*@}

## echo "USER and PASS: $SRC_USERPASS"
echo $SRC_USERPASS | grep /
if [ $? = 0 ]
then
	echo "There is a password"
	export SRC_PASS=${SRC_USERPASS##*/}
	echo "USER only: $SRC_USER"
	echo "PASS only: $SRC_PASS"
	echo "INST: $SRC_INST"
else
	echo "There is NO password"
	echo "You will be prompted for a password during execution"
	echo "USER only: $SRC_USER"
	echo "PASS only: $SRC_PASS"
	echo "INST: $SRC_INST"
fi

hopefully this gets you started, but your parsing will be a bit more complex.

I suggest doing it line by line, then argument by argument.
something like supply the script your xml file, then grep it for the entire summary line. then parse that string for each variable (fatals, testcases, ...) (you will lbe ooking for whatever comes after fatals=" and then before the next ")
then grep the testresults line for the message and result variable.

Let us know how far you get.
Zelp

Hello,

Has anyone got an idea how can I parse the above XML file by using shell script or perl?

Thanks in advance to all who will reply.

Thanks,
racbern

hi

Please try this one:

cat filename | sed  's/<Report.*$/report/' | sed 's/<summary//' | sed 's/\/>//' | sed 's/"//g' | sed 's/<testresult.*message=//'| sed 's/result=.*$//' | sed 's/<\/Report version>//'

Hi Summer Cherry,

I tried your suggestion and it worked..
Thanks a lot for your help.

Regards,
racbern