xml_parse_into_struct(PHP 4, PHP 5) xml_parse_into_struct — Parse XML data into an array structure Описание
int xml_parse_into_struct
( resource $parser
, string $data
, array &$values
[, array &$index
] )
This function parses an XML file 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. Список параметров
Возвращаемые значения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 ===. ПримерыBelow is an example that illustrates the internal structure of the arrays being generated by the function. We use a simple note tag embedded inside a para tag, and then we parse this and print out the structures generated: Пример #1 xml_parse_into_struct() example
<?phpWhen we run that code, the output will be:
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 transversed 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: Пример #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>
Пример #3 parsemoldb.php - parses moldb.xml into an array of molecular objects
<?php
|
|
|
| © 2009 Тест скорости интернета | Boont.Ru |