int xml_parse_into_struct ( resource $parser , string $data , array &$values [, array &$index ] )
This function parses an XML string into 2 parallel array structures, one (index) containing pointers to the location of the appropriate values in the values array. These last two parameters must be passed by reference.
The xml_parse_into_struct() function parses XML data into an array.
Example #2 moldb.xml - small database of molecular information
<?xml version="1.0"?> <moldb> <molecule> <name>Alanine</name> <symbol>ala</symbol> <code>A</code> <type>hydrophobic</type> </molecule> <molecule> <name>Lysine</name> <symbol>lys</symbol> <code>K</code> <type>charged</type> </molecule> </moldb>
After executing parsemoldb.php, the variable $db contains an array of AminoAcid objects, and the output of the script confirms that:
** Database of AminoAcid objects: Array ( [0] => aminoacid Object ( [name] => Alanine [symbol] => ala [code] => A [type] => hydrophobic ) [1] => aminoacid Object ( [name] => Lysine [symbol] => lys [code] => K [type] => charged ) )
Parameter | Description |
---|---|
parser | A reference to the XML parser. |
data | A string containing the XML data. |
values | An array containing the values of the XML data |
index | An array containing pointers to the location of the appropriate values in the $values. |
xml_parse_into_struct() returns 0 for failure and 1 for success. This is not the same as FALSE and TRUE, be careful with operators such as ===.