ronchan Posted September 7, 2008 Share Posted September 7, 2008 I'm using the following to write an XML file: // Write XML $xml_dec = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"; $rootELementStart = "<wrapper>\n\n"; $rootElementEnd = "</wrapper>"; $xml_doc= $xml_dec; $xml_doc .= $rootELementStart; $query ="SELECT *, CONCAT(section,'-',secnum) AS secnumtext FROM captiondata"; // GET RESULTS $result=mysql_query($query) or die("Couldn't execute query"); $numrows=mysql_num_rows($result); while ($row= mysql_fetch_array($result)) { $id = $row["id"]; $secnum = $row["secnum"]; $section = $row["section"]; $title = $row["title"]; $client = $row["client"]; $secnumtext = $row["secnumtext"]; $xml_doc .= "<$secnumtext>\n"; $xml_doc .= "<titletext>\n"; $xml_doc .= "$secnum | $title \n"; $xml_doc .= "</titletext>\n"; $xml_doc .= "<clienttext>\n"; $xml_doc .= "$client \n"; $xml_doc .= "</clienttext>\n"; $xml_doc .= "</$secnumtext>\n\n"; } $xml_doc .= $rootElementEnd; $default_dir = "test.xml"; $fp = fopen($default_dir,'w'); $write = fwrite($fp,$xml_doc); Everything works fine but the XML comes out: <?xml version="1.0" encoding="UTF-8" ?> <wrapper> <peo-01> <titletext> 01 | People Caption </titletext> <clienttext> Super Client, Inc. </clienttext> </peo-01> <peo- 02> <titletext> 02 | People Caption </titletext> <clienttext> Super Client, Inc. </clienttext> </peo- 02> </wrapper> The first section is fine but the subsequent sections all have a break between the "peo-" and the digit rendering it useless. I've tried taking out the dash, making the number a single digit but for some reason is works on the first section but not any section after that. Any help please? Link to comment https://forums.phpfreaks.com/topic/123162-write-xml/ Share on other sites More sharing options...
btherl Posted September 8, 2008 Share Posted September 8, 2008 Are you sure the data in your database is ok? My first impression is that you may have newlines embedded in your secnum column's data. Link to comment https://forums.phpfreaks.com/topic/123162-write-xml/#findComment-636219 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.