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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.