PHP xml_parse_into_struct() Function

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 -

Example #1 xml_parse_into_struct() example

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>

Example #3 parsemoldb.php - parses moldb.xml into an array of molecular objects

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
        )

)

ParameterDescription
parserA reference to the XML parser.
dataA string containing the XML data.
valuesAn array containing the values of the XML data
indexAn 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 ===.