kirk112 Posted October 11, 2007 Share Posted October 11, 2007 I have a script which creates and xml file using the code below. How can I pase this xml file using php. I am currently using xml_parse($xml_parser,file_get_contents($file)); but this get the php code and not the out putted xml. I can't get my head around how to parse the outputted xml using php <?php header('Content-Type: text/xml'); header('Content-Disposition: inline; filename=sample.xml'); include_once('page_config.inc.php'); $vars = get_defined_vars(); print "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>"; print "<root>\n"; foreach($vars['js_type'] as $key => $value) { $v = 'js_type_'.$key; print "<js_config>\n"; print "<array_key>$key</array_key>\n"; print "<header>{$vars[$v]}</header>\n"; print "</js_config>"; } print "</root>\n"; ?> This give me the following xml <?xml version="1.0" encoding="iso-8859-1" ?> - <root> - <js_config> <array_key>1</array_key> <header>ALL JAVASCRIPT FILES</header> </js_config> - <js_config> <array_key>2</array_key> <header>TABS JAVASCRIPT FILES</header> </js_config> - <js_config> <array_key>3</array_key> <header>STANDARD JAVASCRIPT FILES</header> </js_config> </root> Thanks for your help! Link to comment https://forums.phpfreaks.com/topic/72763-solved-php4-and-xml/ Share on other sites More sharing options...
kirk112 Posted October 11, 2007 Author Share Posted October 11, 2007 ** Bump ** tried everything I can think of, there must be a simple way of doing this if i use $file = file_get_contents("../includes/page_config_xml.inc.php"); print nl2br(htmlentities($file)); I get <?php header('Content-Type: text/xml'); header('Content-Disposition: inline; filename=sample.xml'); include_once('page_config.inc.php'); $vars = get_defined_vars(); print "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>"; print "<root>\n"; foreach($vars['js_type'] as $key => $value) { $v = 'js_type_'.$key; print "<js_config>\n"; print "<array_key>$key</array_key>\n"; print "<header>{$vars[$v]}</header>\n"; print "</js_config>"; } print "</root>\n"; ?> instead of the xml only AHHHHHHHHHHHHh Link to comment https://forums.phpfreaks.com/topic/72763-solved-php4-and-xml/#findComment-367052 Share on other sites More sharing options...
kirk112 Posted October 11, 2007 Author Share Posted October 11, 2007 *bump* Link to comment https://forums.phpfreaks.com/topic/72763-solved-php4-and-xml/#findComment-367132 Share on other sites More sharing options...
glenelkins Posted October 11, 2007 Share Posted October 11, 2007 does "echo" work instead of "print" ? Link to comment https://forums.phpfreaks.com/topic/72763-solved-php4-and-xml/#findComment-367144 Share on other sites More sharing options...
kirk112 Posted October 11, 2007 Author Share Posted October 11, 2007 no if I use echo I get <?php header('Content-Type: text/xml'); header('Content-Disposition: inline; filename=sample.xml'); include_once('page_config.inc.php'); $vars = get_defined_vars(); echo "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>"; echo "<root>\n"; foreach($vars['js_type'] as $key => $value) { $v = 'js_type_'.$key; echo "<js_config>\n"; echo "<array_key>$key</array_key>\n"; echo "<header>{$vars[$v]}</header>\n"; echo "</js_config>"; } echo "</root>\n"; ?> Thanks for your help - really can't get my head around this Link to comment https://forums.phpfreaks.com/topic/72763-solved-php4-and-xml/#findComment-367150 Share on other sites More sharing options...
thedarkwinter Posted October 11, 2007 Share Posted October 11, 2007 Sorry, maybe its just me, but im a bit confused about what you are trying to do: Are you trying to parse the xml, or output it to the screen? What should you be getting? Link to comment https://forums.phpfreaks.com/topic/72763-solved-php4-and-xml/#findComment-367159 Share on other sites More sharing options...
kirk112 Posted October 11, 2007 Author Share Posted October 11, 2007 Hi I have one php file that creates and prints out an xml file. What I am trying to do is open the php file (from a seperate script) and get the xml content so that I can manipulate it. But when ever I use fopen, get_file_contents etc all I get is the php script and not the xml content Hope this explains better. Cheers Link to comment https://forums.phpfreaks.com/topic/72763-solved-php4-and-xml/#findComment-367162 Share on other sites More sharing options...
thedarkwinter Posted October 11, 2007 Share Posted October 11, 2007 Ok so maybe in the file that creates the XML, instead of echo'ing or print'ing, use a variable, say $xml so <?php $xml = "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>"; $xml .= "cdcsdcs"; // etc.. and then in your other php file, after you have included this file, just use the variable $xml. <?php //... include("xmlgenerator.php"); // your variable is now set xml_parse($xml) // or whatever echo $xml; im i following you now? hope so tdw Link to comment https://forums.phpfreaks.com/topic/72763-solved-php4-and-xml/#findComment-367169 Share on other sites More sharing options...
ballhogjoni Posted October 11, 2007 Share Posted October 11, 2007 I think this is the best tutorial for parsing xml. It works for me everytime. http://www.ibm.com/developerworks/library/os-xmldomphp/ Link to comment https://forums.phpfreaks.com/topic/72763-solved-php4-and-xml/#findComment-367254 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.