Home: Perl Programming Help: Advanced:
Parse XML file



apatil65
New User

Aug 27, 2014, 6:52 AM


Views: 24736
Parse XML file

Here is the sample XML:

<Sport Name=“Kabaddi” TimeStamp="10/09/14 04:53:58">
<EventGroup name="Royal" ID="20394662">
<Event Name="Warwickshire vs Durham" ID="-487050038">
<Market Name="To Win">
<Participant Name="Warwickshire" Adds="10/11" />
<Participant Name="Durham" Adds="10/11" />
</Market>
</Event>
</EventGroup>
<EventGroup name="Ireland v Scotland 2nd ODI " ID="20395014">
<Event Name="Ireland vs Scotland - 2nd ODI " ID="-1006438617">
<Market Name="To Win>
<Participant Name="Ireland" Adds="10/11" />
<Participant Name="Scotland" Adds="10/11"/>
<Participant Name="Durham" Adds="10/11" />
</Market>
</Event>
</EventGroup>
</Sport>

In this xml file, if the Market Name is "To Win", then i want to fetch all the "Participant Names". Please help me with this.

Code

In Reply To


(This post was edited by apatil65 on Sep 10, 2014, 2:22 AM)


Laurent_R
Veteran / Moderator

Aug 27, 2014, 12:01 PM


Views: 24731
Re: [apatil65] Parse XML file

Please provide an example. I fail to see how an XML file might have array references or hash references or both. It is probably a misunderstanding, but please explain and provide sample data.


apatil65
New User

Sep 10, 2014, 8:52 PM


Views: 22591
Re: [Laurent_R] Parse XML file

Here is the sample XML:

<Sport Name=“Kabaddi” TimeStamp="10/09/14 04:53:58">
<EventGroup name="Royal" ID="20394662">
<Event Name="Warwickshire vs Durham" ID="-487050038">
<Market Name="To Win">
<Participant Name="Warwickshire" Adds="10/11" />
<Participant Name="Durham" Adds="10/11" />
</Market>
</Event>
</EventGroup>
<EventGroup name="Ireland v Scotland 2nd ODI " ID="20395014">
<Event Name="Ireland vs Scotland - 2nd ODI " ID="-1006438617">
<Market Name="To Win>
<Participant Name="Ireland" Adds="10/11" />
<Participant Name="Scotland" Adds="10/11"/>
<Participant Name="Durham" Adds="10/11" />
</Market>
</Event>
</EventGroup>
</Sport>

In this xml file, if the Market Name is "To Win", then i want to fetch all the "Participant Names". Please help me with this.

Code

In Reply To


Laurent_R
Veteran / Moderator

Sep 11, 2014, 10:28 AM


Views: 22539
Re: [apatil65] Parse XML file

It is considered unfair to change a post after someone has answered to it without at least clearly indicating what you add, what you change and what you delete. Now my previous question looks stupid and off-topic, because it was answering to a totally different post in which there was no XML sample and in which you were speaking about an XML file having array references or hash references.

Please don't do that.