Jump to content

XML reader record count problem


andrewgerm

Recommended Posts

Hi all

 

I've been working on a problem with XMLreader for some time now, and have been stuck on an issues I think is related to reading several attributes from one element. Not sure if this is the case though, but the manual for xmlreader is sorely lacking info.

 

My XML looks similar to

<xml>

<company>

- about a hundred of these

</company>

<appointment start='0100' end='0200' id='123'>

<subject></subject>

<location></location>

<comment></comment>

</appointment> - about half a million of these

 

My PHP is:

while($oXML->read()) 
{ 
if($oXML->nodeType == XMLReader::ELEMENT) 
{ 
if($oVidXML->localName == 'appointment') 
{ 
$Varstart = $oXML->getAttribute('start'); 
$Varstop = $oXML->getAttribute('stop'); 
$Varid = $oXML->getAttribute('id'); 
echo $i; 
} 
else if 
{ 
$oVidXML->read(); 
$Varsubject = $oVidXML->value; 
echo $i; 
} 
$i++; 
} 
else if($oML->nodeType == XMLReader::END_ELEMENT && $oML->localName == 'subject') 
{ 
// submit SQL 
} 

 

Any help would be appreciated.

 

The input file can easily contain half to a million records, and Gzipped is about 10MB (easily uncompressing to about 70 odd.

 

What is happening, is that I am successfully getting the 'start', 'stop' and 'id' data. But it seems that the while loop is running a further two iterations, and then is grabbing the subject, as the value of $i differs by 2. There for, I am getting empty variables (first first round gets the first 3 pieces of info, and then iteration, and then the subject info.

 

Any and all help would be appreciated.

 

Thank you in advance.

Link to comment
https://forums.phpfreaks.com/topic/232903-xml-reader-record-count-problem/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.