Jump to content

Write XML


ronchan

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.