You are here:  » reading XML file


reading XML file

Submitted by baggagepin on Sat, 2009-12-19 19:15 in

Hi,

I am trying to use a very simple script to read my XML file:

How do I make the script just read the "Public" tags in the XML file.

<?php
  
require("MagicParser.php");
  function 
myRecordHandler($record)
  {
    
print_r($record);
  }
  
$result MagicParser_parse("flightdata.xml","myRecordHandler","xml|Envelope/header/body/public/");
  if (!
$result)
  {
    print 
MagicParser_getErrorMessage();
  }
?>

MY XML FILE

<?xml version="1.0" encoding="UTF-8"?>
<Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://xmlrepository/AOS/Controlled/AFDS/Schemas/AFDSFlightData_2.xsd">
    <Header>
        <MessageSentDateTime>2009-07-02T00:00:21Z</MessageSentDateTime>
        <MessageSequenceNumber>727956</MessageSequenceNumber>
        <MessageType>AFDSFlightData</MessageType>
        <SourceSystemID>IDAHO</SourceSystemID>
        <DestinationSystemID>FIDS</DestinationSystemID>
    </Header>
    <Body>
        <AFDSFlightData>
            <SubscriptionID>134784</SubscriptionID>
            <Identification>
                <AODBUniqueID>4545802</AODBUniqueID>
                <FlightReference>
                    <CarrierCode>TCX</CarrierCode>
                    <FlightNumber>121</FlightNumber>
                    <FlightSuffix>L</FlightSuffix>
                    <ArrivalOrDeparture>A</ArrivalOrDeparture>
                    <ScheduledDateTime>2009-07-02T00:30:00Z</ScheduledDateTime>
                </FlightReference>
            </Identification>
            <Aircraft>
                <AircraftRegistration>GFCLJ</AircraftRegistration>
                <IATAAircraftTypeCode>752</IATAAircraftTypeCode>
            </Aircraft>
            <Airport>
                <BaggageReclaim>
                    <BaggageReclaimID xsi:nil="true"/>
                    <BaggageReclaimRole>Primary</BaggageReclaimRole>
                </BaggageReclaim>
                <BaggageReclaim>
                    <BaggageReclaimID xsi:nil="true"/>
                    <BaggageReclaimRole>Secondary</BaggageReclaimRole>
                </BaggageReclaim>
                <GateNumber xsi:nil="true"/>
                <GateType>Standard</GateType>
                <HostAirportCode>LGW</HostAirportCode>
                <PierCode xsi:nil="true"/>
                <PreviousGate xsi:nil="true"/>
                <RunwayID xsi:nil="true"/>
                <SecondTerminalCode xsi:nil="true"/>
                <TerminalCode>S</TerminalCode>
            </Airport>
            <CodeShares>
                <CodeShare xsi:nil="true"/>
            </CodeShares>
            <Control>
                <DataOperationType>Amend</DataOperationType>
                <FIDSBaggageHallActive>N</FIDSBaggageHallActive>
                <FIDSFlightActive>Y</FIDSFlightActive>
                <FIDSRollOnDateTime>2009-07-01T12:30:00Z</FIDSRollOnDateTime>
            </Control>
            <Flight>
                <FlightStatus>ZN</FlightStatus>
                <IATAServiceType>C</IATAServiceType>
                <InternationalOrDomestic>I</InternationalOrDomestic>
                <LinkedFlight>
                    <CarrierCode>TCX</CarrierCode>
                    <FlightNumber>407</FlightNumber>
                    <FlightSuffix>K</FlightSuffix>
                    <ArrivalOrDeparture>D</ArrivalOrDeparture>
                    <ScheduledDateTime>2009-07-02T05:15:00Z</ScheduledDateTime>
                </LinkedFlight>
            </Flight>
            <GroundMovements/>
            <Load>
                <TotalBaggageWeight>0</TotalBaggageWeight>
                <TotalFreightWeight>0</TotalFreightWeight>
                <TotalMailWeight>0</TotalMailWeight>
                <TotalPassengerCount>180</TotalPassengerCount>
            </Load>
            <OperationalTimes>
                <EstimatedDateTime>2009-07-02T00:09:00Z</EstimatedDateTime>
                <OperatedDateTime xsi:nil="true"/>
            </OperationalTimes>
            <PortsOfCall>
                <PortOfCall>
                    <IATACountryCode>EG</IATACountryCode>
                    <IATALocationCode>SSH</IATALocationCode>
                    <ICAOLocationCode>HESH</ICAOLocationCode>
                    <PublicLocationName>Sharm El Sheikh</PublicLocationName>
                    <ShowToPublic>Y</ShowToPublic>
                </PortOfCall>
            </PortsOfCall>
            <Public>
                <FlightIdentifier>
                    <CarrierCode>TCX</CarrierCode>
                    <FlightNumber>121</FlightNumber>
                    <FlightSuffix>L</FlightSuffix>
                </FlightIdentifier>
                <PublicGateNumber xsi:nil="true"/>
                <Times>
                    <EstimatedDateTime xsi:nil="true"/>
                    <OperatedDateTime xsi:nil="true"/>
                    <ScheduledDateTime>2009-07-02T01:30:00+01:00</ScheduledDateTime>
                </Times>
                <StatusMessages>
                    <StatusMessage>
                        <FIDSDisplayMode>S</FIDSDisplayMode>
                        <FIDSDisplayZone>STLsIntArr</FIDSDisplayZone>
                        <StatusMessageText>Expected 02:11</StatusMessageText>
                    </StatusMessage>
                </StatusMessages>
            </Public>
            <StandAllocations>
                <Stand>20M</Stand>
            </StandAllocations>
        </AFDSFlightData>
    </Body>
</Envelope>

Submitted by support on Sat, 2009-12-19 23:27

Hello,

The Format String that you are using is not quite correct. For the PUBLIC element, it should be:

xml|ENVELOPE/BODY/AFDSFLIGHTDATA/PUBLIC/

...so if you use as your source code:

  $result = MagicParser_parse("flightdata.xml","myRecordHandler","xml|ENVELOPE/BODY/AFDSFLIGHTDATA/PUBLIC/");

...that should do the trick!

Demo Link

Cheers,
David.
--
MagicParser.com

Submitted by baggagepin on Sat, 2009-12-19 23:41

Hi David,

Thanks for pointing my error out to me.

Great Script.

Many thanks

Dereck