All articles(网络文学目录) All Pictures(图片目录) All Softwares(软件目录)

 
PHP解析XML,元素结构范例_php资料_编程技术

Writer: aaa Article type: Programming skills(编程技巧) Time: 2013/12/21 22:34:37 Browse times: 421 Comment times: 0

PHP解析XML,元素结构范例_php资料_编程技术


Head photo

Go homepage
Upload pictures
Write articles

PHP解析XML 元素结构范例_php资料_编程技术-你的首页-uuhomepage.com

  该范例用缩进格式显示一个文档中起始元素的结构。

  显示 XML 元素结构

$file = "data.xml";
$depth = array();

function startElement($parser, $name, $attrs) {
global $depth;
for ($i = 0; $i < $depth[$parser]; $i++) {
print " ";
}
print "$name\n";
$depth[$parser]++;
}

function endElement($parser, $name) {
global $depth;
$depth[$parser]--;
}

$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startElement", "endElement");
if (!($fp = fopen($file, "r"))) {
die("could not open XML input");
}

while ($data = fread($fp, 4096)) {
if (!xml_parse($xml_parser, $data, feof($fp))) {
die(sprintf("XML error: %s at line %d",
xml_error_string(xml_get_error_code($xml_parser)),
xml_get_current_line_number($xml_parser)));
}
}
xml_parser_free($xml_parser);
?>





There are 0 records,
Comment:
Must be registered users to comment(必须是注册用户才能发表评论)

Disclaimer Privacy Policy About us Site Map
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.