How to query a xml file and fill to an array?
Posted: 19 Nov 2014, 05:38
I know I can query the xml file with xpath. That's the sample xml I was using.
What I want achive is select all the events where Msg_type=2, then put the LocationX , LocationY, Name to an array with selected events.
For now , I use xpath with expression "//Msg/Event[@Msg_type=2]/@ LocationX", the result supposed to be :
but what I got is:
How can I get all the events which match the condition? And can I put thems in an string array?
Thanks for you suggestion!
Code: Select all
<Data_file>
<Game id="2221111">
<Msg>
<Event Event_num="110" Msg_type="0"
LocationX="0" LocationY="0" Name="" />
<Event Event_num="111" Msg_type="2"
LocationX="10" LocationY="50" Name="James" />
<Event Event_num="112" Msg_type="2"
LocationX="0" LocationY="-50" Name="Peter" />
<Event Event_num="113" Msg_type="2"
LocationX="50" LocationY="60" Name="Martin" />
</Msg>
</Game>
</Data_file>
For now , I use xpath with expression "//Msg/Event[@Msg_type=2]/@ LocationX", the result supposed to be :
Code: Select all
10
0
50
Code: Select all
10
Thanks for you suggestion!