PHP XMLREADER - QUESTION

Posted by Matias on Stack Overflow See other posts from Stack Overflow or by Matias
Published on 2010-05-12T17:15:24Z Indexed on 2010/05/12 17:34 UTC
Read the original article Hit count: 203

Filed under:
|

Hi Guys,

I am pretty new to xml parsing and I am using XMLREADER to parse a huge file.

Given the following XML (sample):

<hotels>
 <hotel>
   <name>Bla1</name>
 </hotel>
 <hotel>
  <name>Bla2</name>
 </hotel>
</hotels>

And then the XMLREADER in PHP which pulls up the values to my Database:

$reader = new XMLReader();
$reader->open('hotels.xml');
while ($reader->read()) {

 if ($reader->name == "name") {

   $reader->read();
   mysql_query("INSERT INTO MyHotels (hotelName) VALUES (\"$reader->value\")");
 }

}
$reader->close();

The problem is that I've got a single empty row between each of the parsed nodes!! Not sure why this happens!

 | ID | hotelName |
 | 1  | Bla1      |
 | 2  |           |
 | 3  | Bla2      |
 | 4  |           |

Help is greatly appreciated.

© Stack Overflow or respective owner

Related posts about php5

Related posts about xmlreader