xml_parse_into_struct

PHP 4, PHP 5, PHP 7, PHP 8
xml_parse_into_struct - Parse XML data into an array structure
Manual
Code Examples

Example #1 xml_parse_into_struct example

tag, and then we parse this and print out the structures generated:
Result: Index array Array ( [PARA] => Array ( [0] => 0 [1] => 2 ) [NOTE] => Array ( [0] => 1 ) ) Vals array Array ( [0] => Array ( [tag] => PARA [type] => open [level] => 1 ) [1] => Array ( [tag] => NOTE [type] => complete [level] => 2 [value] => simple note ) [2] => Array ( [tag] => PARA [type] => close [level] => 1 ) )
PHP Version:

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

And some code to parse the document and generate the appropriate objects:

PHP Version:

Example #3 moldb.xml - small database of molecular information

Event-driven parsing (based on the expat library) can get complicated when you have an XML document that is complex. This function does not produce a DOM style object, but it generates structures amenable of being traversed in a tree fashion. Thus, we can create objects representing the data in the XML file easily. Let's consider the following XML file representing a small database of aminoacids information:

PHP Version: