时间:2021-07-01 10:21:17 帮助过:7人阅读
参数说明:@param-->$parser XML解析器,由xml_parser_create()生成一个XML资源句柄。
@param-->$data 带解析的XML字符串。
@param--> &$value 解析完成后生成的数据数组。
通常包括:1. 标签名字,例如
2. 标签所处状态(或者说是类型),
3. 当前元素所处XML解析数的第几层(XML通常被解析为一颗倒置树,根(顶层元素)处于第一层 )比如
4. 可选的值。在例子
@param-->&$index 解析完成后生成的对应数组$value中元素取值的索引数组,从 0 开始统计。比如在
举例:
XML;$parse = xml_parser_create();xml_parser_set_option($parse, XML_OPTION_CASE_FOLDING, 1);xml_parser_set_option($parse, XML_OPTION_SKIP_WHITE, 1);$val = array();$index = array();xml_parse_into_struct($parse, $xml, $val, $index);echo " Alanine ala A
hydrophobic Lysine lys K
charged ";print_r($val);echo "";?>
";print_r($index);echo "
Array( [0] => Array ( [tag] => MOLDB [type] => open [level] => 1 ) [1] => Array ( [tag] => MOLECULE [type] => open [level] => 2 ) [2] => Array ( [tag] => NAME [type] => complete [level] => 3 [value] => Alanine ) [3] => Array ( [tag] => SYMBOL [type] => complete [level] => 3 [value] => ala ) [4] => Array ( [tag] => CODE [type] => complete [level] => 3 [value] => A ) [5] => Array ( [tag] => TYPE [type] => complete [level] => 3 [value] => hydrophobic ) [6] => Array ( [tag] => MOLECULE [type] => close [level] => 2 ) [7] => Array ( [tag] => MOLECULE [type] => open [level] => 2 ) [8] => Array ( [tag] => NAME [type] => complete [level] => 3 [value] => Lysine ) [9] => Array ( [tag] => SYMBOL [type] => complete [level] => 3 [value] => lys ) [10] => Array ( [tag] => CODE [type] => complete [level] => 3 [value] => K ) [11] => Array ( [tag] => TYPE [type] => complete [level] => 3 [value] => charged ) [12] => Array ( [tag] => MOLECULE [type] => close [level] => 2 ) [13] => Array ( [tag] => MOLDB [type] => close [level] => 1 ))Array( [MOLDB] => Array ( [0] => 0 [1] => 13 ) [MOLECULE] => Array ( [0] => 1 [1] => 6 [2] => 7 [3] => 12 ) [NAME] => Array ( [0] => 2 [1] => 8 ) [SYMBOL] => Array ( [0] => 3 [1] => 9 ) [CODE] => Array ( [0] => 4 [1] => 10 ) [TYPE] => Array ( [0] => 5 [1] => 11 ))
<--0--> <--13--><--1--> <--6-->Alanine <--2-->ala <--3-->A
<--4-->hydrophobic <--5--><--7--> <--12-->Lysine <--8-->lys <--9-->K
<--10-->charged <--11-->