Access the answers to your technology questions today.
Subscribe Now
30-day free trial. Register in 60 seconds.
What Makes Experts Exchange Unique?
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.
Try it out and discover for yourself.
Subscribe Now
30-day free trial. Register in 60 seconds.
Join the Community
Give a Little. Get a Lot.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Join the Community
by: jkna_gunnPosted on 2004-12-14 at 15:50:58ID: 12825605
try this out, ive tested it on your file you mentioned above, although you forgot to end the tag on secondname which caused me a few headaches till i noticed.
Parser, XML_OPTION_CASE_FOLDING, false); mlParser, "startElement", "endElement"); dler($xmlP arser, "characterData");
);
"cdata"]) . "<br>"; "cdata"]) . "<br>"; "cdata"]) . "<br>"; "cdata"]) . "<br>"; "cdata"]) . "<br>";
attrs"=>$a ttrs);
data']=$da ta;
hildren'][ ] = $stack[count($stack)-1];
<?php
$stack = array();
readXml("./test.xml");
// Reads XML file into formatted html
function readXML($xmlFile)
{
global $stack;
$xmlParser = xml_parser_create();
xml_parser_set_option($xml
xml_set_element_handler($x
xml_set_character_data_han
$fp = fopen($xmlFile, "r");
while($data = fread($fp, filesize($xmlFile))){
xml_parse($xmlParser, $data, feof($fp));}
xml_parser_free($xmlParser
print ($stack[0]["children"][0][
print ($stack[0]["children"][1][
print ($stack[0]["children"][2][
print ($stack[0]["children"][3][
print ($stack[0]["children"][4][
}
// Sets the current XML element, and pushes itself onto the element hierarchy
function startElement($parser, $name, $attrs)
{
global $stack;
$tag=array("name"=>$name,"
array_push($stack,$tag);
}
// Prints XML data; finds highlights and links
function characterData($parser, $data)
{
global $stack;
if(trim($data))
{
$stack[count($stack)-1]['c
}
}
// If the XML element has ended, it is poped off the hierarchy
function endElement($parser, $name)
{
global $stack;
$stack[count($stack)-2]['c
array_pop($stack);
}
?>