seangamer Posted September 11, 2008 Share Posted September 11, 2008 Hello, everyone! I'm new to this forum, but from the looks of things this is a widely used forum so hopefully there will be someone here who can help me. Thanks in advance! Background: I have a simple XML file that references other XML files in a table of contents type manner using entities. I use SimpleXML to access and process this XML file and return a list of its contents. (No I don't want to use XSLT). Before I started using entities everything worked wonderfully, but after I changed the XML file (I've not touched the PHP file) everything stopped working. I know what the problem is I just don't know how to fix it... My Problem: When I print the array returned from opening the XML file I get both XML entities (inside the first entity array), but I also then get a third, repeated, printout of the second entity (inside the second entity array). I tried removing one entity at a time from the XML file and each time it printed out just one array like it should, but once I have both it prints three. Is this a bug or am I doing something wrong? My Code: main.html - try print_r to see what I mean about the entity arrays and yes I know that I need to update this so it encludes the entity elements. <html><head><title></title></head> <body><ul> <?php $xml=simple_xml_loadfile('main.xml'); foreach($xml->section as $section) { echo($section['title']); foreach($section->page as $page) { echo($section['location'].$page['location']); } } ?> </ul></body> </html> main.xml <?xml version="1.0"?> <!DOCTYPE range[ <!entity test1 system "../xml/t1/test1.xml"> <!entity test2 system "../xml/t2/test2.xml"> ]> <range>&test1;&test2;</range> test1.xml & test2.xml - Just switch all the 1's to 2's <section title="Test 1" location="../xml/t1/test1.xml"> <page location="test1.php" /> ... </section> Thanks again for any help! Link to comment https://forums.phpfreaks.com/topic/123782-simplexmlxml-entity-problem-advanced/ Share on other sites More sharing options...
seangamer Posted September 15, 2008 Author Share Posted September 15, 2008 Well... I got an answer from another forum that looks like it should work. Here's the solution should anyone find this thread here with the same problem. Replace the load file command with the following command. $xml=simplexml_load_file('main.xml', NULL, LIBXML_NOENT); Link to comment https://forums.phpfreaks.com/topic/123782-simplexmlxml-entity-problem-advanced/#findComment-641630 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.