PHP解析XML 元素结构范例_PHP
Jun 01, 2016 pm 12:29 PM该范例用缩进格式显示一个文档中起始元素的结构。
显示 XML 元素结构
$file = "data.xml";
$depth = array();
function startElement($parser, $name, $attrs) {
global $depth;
for ($i = 0; $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);
?>

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Detailed explanation of Oracle error 3114: How to solve it quickly

Analysis of new features of Win11: How to skip logging in to Microsoft account

Analysis of the meaning and usage of midpoint in PHP

Apache2 cannot correctly parse PHP files

Parsing Wormhole NTT: an open framework for any Token

Comparison of Java libraries for XML parsing: Finding the best solution

What are the syntax and structure characteristics of lambda expressions?

In-depth analysis of the structure and purpose of the MySQL.proc table
