You are here:  » Specifying Attributes to Return?


Specifying Attributes to Return?

Submitted by cogden on Wed, 2006-10-04 21:27 in

I have to parse rather large XML files (~7+MB) and update a series of mySQL tables. Is there any way to specify what attribute(s) to return (in XPATH parlance, something like "attribute::userid")?

Submitted by support on Wed, 2006-10-04 22:06

Hi,

There's no way to limit the number of attributes that are included in the record array that is passed to your record handler function. It is simply down to your application to make use of the attributes required.

The key names in the record array (as passed to your record handler function) for attributes are separated from thier associated element by a hyphen, so for example, if a record within your XML document contained:

<employee id='1234'>Example</employee>

...then you would access the id within the record handler as follows:

<?php
  
function myRecordHandler($record)
  {
    print 
$record["EMPLOYEE-ID"];
  }
?>

The easiest way to see what keys to use is to use the print_r() function on $record when you first start working with a new XML document - this will show you what key/value pairs are present in the $record array.

Hope this helps!
Cheers,
David.