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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.