I've been trying to parse a very large XML file with PHP and XMLReader, but can't seem to get the results I am looking for. Basically, I'm searching a ton of information, and if a contains a certain zipcode, I'd like to return that bit of XML, or keep searching until it finds that zipcode. Essentially, I'll be breaking this big file down into only a few small chunks, so instead of having to look at thousands or millions of groups of information, it would be maybe 10's or 20's.
Here's a bit of the XML with what I'd like to
//search through xml
<lineups country="USA">
//cache TX02217 as a variable
<headend headendId="TX02217">
//cache Grande Gables at The Terrace as a variable
<name>Grande Gables at The Terrace</name>
//cache Grande Communications as a variable
<mso msoId="17541">Grande Communications</mso>
<marketIds>
<marketId type="DMA">635</marketId>
</marketIds>
//check to see if any of the postal codes are equal to $pc variable that will be set in the php
<postalCodes>
<postalCode>11111</postalCode>
<postalCode>22222</postalCode>
<postalCode>33333</postalCode>
<postalCode>78746</postalCode>
</postalCodes>
//cache Austin to a variable
<location>Austin</location>
<lineup>
//cache all prgSvcID's to an array i.e. 20014, 10722
<station prgSvcId="20014">
//cache all channels to an array i.e. 002, 003
<chan effDate="2006-01-16" tier="1">002</chan>
</station>
<station prgSvcId="10722">
<chan effDate="2006-01-16" tier="1">003</chan>
</station>
</lineup>
<areasServed>
<area>
//cache community to a variable $community
<community>Thorndale</community>
<county code="45331" size="D">Milam</county>
//cache state to a variable i.e. TX
<state>TX</state>
</area>
<area>
<community>Thrall</community>
<county code="45491" size="B">Williamson</county>
<state>TX</state>
</area>
</areasServed>
</headend>
//if any of the postal codes matched $pc
//echo back the xml from <headend> to </headend>
//if none of the postal codes matched $pc
//clear variables and move to next <headend>
<headend>
etc
etc
etc
</headend>
<headend>
etc
etc
etc
</headend>
<headend>
etc
etc
etc
</headend>
</lineups>
PHP:
<?php
$pc = "78746";
$xmlfile="myFile.xml";
$reader = new XMLReader();
$reader->open($xmlfile);
while ($reader->read()) {
//search to see if groups contain $pc and echo info
}
I know I'm making this harder than it should be but am a little overwhelmed trying to manipulate such a large file. Any help is appreciated.