Operating System - HP-UX
1820298 Members
3078 Online
109622 Solutions
New Discussion юеВ

Re: How to read tag values from xml file?

 
SOLVED
Go to solution
diwakar_4
Frequent Advisor

How to read tag values from xml file?

Hi All,

I have to generate report out of xml file.

xml file is like :
********************************************
ghghghgf

0345
001


0345
001


JN001TEST2
*******************************************

Out of many tags i want to read tag like , under sender tag and store their value in some var.
Can some one suggest how to read these tags.

Thanks
4 REPLIES 4
Steven E. Protter
Exalted Contributor

Re: How to read tag values from xml file?

Shalom,

grep "" > tempfile

I think grep is the right tool go grab what you want and process it into reports.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
diwakar_4
Frequent Advisor

Re: How to read tag values from xml file?

Hi,

Thanks,

I have bit tricy part to do like.


0345
001


How to read these two values lie under tag, becasue if i grep i get many values for tag.

Thanks
Hein van den Heuvel
Honored Contributor
Solution

Re: How to read tag values from xml file?


If the input predictably as shown, then you can hack a solution with awk or perl like:

$ awk -F'[<>]' '//,/<\/Sender>/{if ($2=="OrganisationID") org=$3; if ($2=="DistrictID") dis=$3} END {print dis,org}' x
001 0345

So this looks for records between send and /sender, and splits based on < or >.
Thus the tag become $1, the value $3.

But please do yourself a favor and google for '+perl +xml' and check out some general purpose solution like the perl XML::Simple.
This things will hand odd line breaks, single lines input, deeper nesting, and so on.

http://articles.techrepublic.com.com/5100-10878_11-5363190.html

hth,
Hein.
diwakar_4
Frequent Advisor

Re: How to read tag values from xml file?

Hi Hein van den,

Many thanks,

I will explore it more.

Thanks