vimal kumar

vimal kumar

  • NA
  • 3
  • 0

Parsing a XML file

Sep 2 2009 8:11 AM

Hi i had been using XercersDomParser for parsing the XML file in C++
I am not familiar with XML. In the follwing XML file
<?xml version="1.0" encoding="UTF-8"?>
<Locomotives>
  <Locomotive xmlns="http://localhost:8080/source/schemas/locomotive.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://localhost:8080/source/schemas/locomotive.xsd http://localhost:8080/source/schemas/locomotive.xsd">
    <LocoId>9001</LocoId>
    <LocoRunNumber>UnReg</LocoRunNumber>
    <LocomotiveGPSData>
      <SampleTime>2008-07-13T13:37:33</SampleTime>
      <Latitude>-32.86693333</Latitude>
      <Longitude>151.75333333</Longitude>
      <Speed>-1</Speed>
      <Direction>-1</Direction>
      <KmPostPosition>178500</KmPostPosition>
      <TrackNumber>85</TrackNumber>
    </LocomotiveGPSData>
    <Events>
      <Alarms>0</Alarms>
      <Faults>0</Faults>
    </Events>

  </Locomotive>
  <Locomotive xmlns="
http://localhost:8080/source/schemas/locomotive.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://localhost:8080/source/schemas/locomotive.xsd http://localhost:8080/source/schemas/locomotive.xsd">
    <LocoId>9002</LocoId>
    <LocoRunNumber>UnReg</LocoRunNumber>
    <LocomotiveGPSData>
      <SampleTime>2008-07-13T23:59:56</SampleTime>
      <Latitude>-32.61888333</Latitude>
      <Longitude>151.14988333</Longitude>
      <Speed>-1</Speed>
      <Direction>-1</Direction>
      <KmPostPosition>239000</KmPostPosition>
      <TrackNumber>87</TrackNumber>
    </LocomotiveGPSData>
    <Events>
      <Alarms>0</Alarms>
      <Faults>0</Faults>
    </Events>
</Locomotives> 
Eventhough i can traverse through XML file through
DOMTreeWalker but can't get idea to store Values in a strucured <list>

the structure look like this

typedef
struct
{
Loco_Id LocoId ;
string
/*DateTime*/ SampleTime ;
float Lattitude;
float Longitude;
float Speed ;
float Direction;
int KmPostPosition;
int TrackNumber;
int Alarms;
int Failures ;
}LocoDetails

Can any one tell how to access the value from the XML file and store to a list

Answers (1)