LonghornPHP 2026

Ejemplo de estructura XML

Este primer ejemplo muestra la estructura del elemento de inicio en un documento con indentación.

Ejemplo #1 Mostrar una estructura XML

<?php
$file = "examples/book.xml";
$depth = 0;
function startElement($parser, $name, $attrs)
{
 global $depth;
 global $depth;
 for ($i = 0; $i < $depth; $i++) {
 echo " ";
 }
 echo "$name\n";
 $depth++;
}
function endElement($parser, $name)
{
 global $depth;
 $depth--;
}
$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("Error XML: %s en la línea %d",
 xml_error_string(xml_get_error_code($xml_parser)),
 xml_get_current_line_number($xml_parser)));
 }
}
?>

Found A Problem?

Learn How To Improve This PageSubmit a Pull RequestReport a Bug
+add a note

User Contributed Notes

There are no user contributed notes for this page.

AltStyle によって変換されたページ (->オリジナル) /