Thread: XML Parsing

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2014
    Posts
    2
    Rep Power
    0

    XML Parsing


    I am new in shell script
    Can any one help me in XML parsing,
    I need to read values from XML file and import values to csv file (generate csv file at run time) using shell script.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2006
    Posts
    2,441
    Rep Power
    1688
    One has to say 'why?' Use something that can actually, with minimal effort, parse XML, such as perl, with one or more available modules.
    The moon on the one hand, the dawn on the other:
    The moon is my sister, the dawn is my brother.
    The moon on my left and the dawn on my right.
    My brother, good morning: my sister, good night.
    -- Hilaire Belloc
  4. #3
  5. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,996
    Rep Power
    9397
    In other words, a shell script per se is probably not the best option, and you should go with a script written in some other programming language (eg, Perl, Python, PHP) that has actual XML parsing features (eg, XML::Simple, ElementTree, SimpleXML) to do it instead.
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2014
    Posts
    2
    Rep Power
    0
    I need to parsing below xml and read ID, Event_Date and DID from XMl

    <Transaction_details><Transaction ChannelType="used" OID="PRODUCTIOn" TransactionID="1">
    <Resource maintype="DASE">
    <ResourceDASE subtype="AAA" Seq="1">
    <ID>GFG4A5</ID>
    <Number>U6</Number>
    </ResourceDASE>
    <ResourceE subtype="ESN" Seq="1">
    <E>H2RM</E>
    </ResourceEsn>
    <ResourceEvent subtype="DASE_Event" Seq="1">
    <Event_Name>Sold</Event_Name>
    <Event_Date>2014-01-10</Event_Date>
    <Event_seq>1</Event_seq>
    <SubscriptionDetails>
    <Code>DMINCP</Code>
    </SubscriptionDetails>
    <Type>Rent</Type>
    <Ind>false</Ind>
    <DID>H1108</ID>
    </ResourceEvent>
    </Resource>
    </Transaction>
    <Transaction ChannelType="used" OID="PRODUCTIOn" TransactionID="2">
    <Resource maintype="DASE">
    <ResourceDASE subtype="AAA" Seq="1">
    <ID>1FAHP3L3</ID>
    <Number>U4</Number>
    </ResourceDASE>
    <ResourceEsn subtype="ESN" Seq="1">
    <E>0478</E>
    </ResourceEsn>
    <ResourceEvent subtype="DASE_Event" Seq="1">
    <Event_Name>Sold</Event_Name>
    <Event_Date>2014-01-10</Event_Date>
    <Event_seq>1</Event_seq>
    <SubscriptionDetails>
    <Code>DMIN</Code>
    </SubscriptionDetails>
    <Type>Retail</Type>
    <Ind>false</Ind>
    <DID>E1108</DID>
    </ResourceEvent>
    </Resource>
    </Transaction>
    <Transaction ChannelType="used" OID="PRODUCTIOn" TransactionID="3">
    <Resource maintype="DASE">
    <ResourceDASE subtype="AAA" Seq="1">
    <ID>3GNVKGE0</ID>
    <Number>U4</Number>
    </ResourceDASE>
    <ResourceE subtype="E" Seq="1">
    <E>4WVV</E>
    </ResourceE>
    <ResourceEvent subtype="DASE_Event" Seq="1">
    <Event_Name>DASESold</Event_Name>
    <Event_Date>2014-01-13</Event_Date>
    <Event_seq>1</Event_seq>
    <SubscriptionDetails>
    <Code>O3MO</Code>
    </SubscriptionDetails>
    <Type>Retail</Type>
    <Ind>false</Ind>
    <DID>4284</DID>
    </ResourceEvent>
    </Resource>
    </Transaction>

    Can you please help me , it would be really Appreciate.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2006
    Posts
    2,441
    Rep Power
    1688
    I hope you didn't type that in by hand! Then again I hope you did as the first DID element has an invalid terminator (it has /ID instead of /DID).

    Anyway, as suggested, a language that has extensions available that permits easy parsing of XML (a few have been mentioned already) would be the best way to go. I gather that you do not have a lot of experience with *nix shells and I'd also make the assumption you are also not that familiar with python, perl or php.

    I am not sure what base languages you have already installed on the computer in question but I would pick one, take a look at it, work out how to add the required XML parsing module/add-on and give that a go. Which one you use will be down to how you get on with each of the languages. Personally, perl makes me shudder, but I have used it and if you write it yourself it's not so bad; python is quite nice but has 'quirks' regarding indentation of code; php is ... well, php!
    The moon on the one hand, the dawn on the other:
    The moon is my sister, the dawn is my brother.
    The moon on my left and the dawn on my right.
    My brother, good morning: my sister, good night.
    -- Hilaire Belloc

IMN logo majestic logo threadwatch logo seochat tools logo