php xml output OK, but missing version header?
Posted: Sun Jun 13, 2010 12:13 am
I'm using php 4.3.11 (no choice, I have to) and the dump_file method for writing an XML file. All is fine in terms of the tree, but I can't get the first line (xml version) to be output.
It should be:
<?xml version="1.0"?>
I've tried:
I also tried:
(which does generate a first line, but as a comment, of course).
And I tried
I am missing something obvious? How do I get the first line of output in the *.xml file to be the version info??
The only I idea I have is to work with two files and fopen/fread/fwrite, but that seems a roundabout way...
Every example I see has the same approach, but shows the first line. (Note, I have to use dump_file or something similar.)
fyi, here is my generated xml file - I just need the first line to be added:
here is the first part and last part of the script:
It should be:
<?xml version="1.0"?>
I've tried:
Code: Select all
<?php
header('Content-Type: text/xml');
...Code: Select all
<?php
$dom = domxml_new_doc('1.0');
$hdr = "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>";
$topper = $dom->create_comment($hdr);
$topper = $dom->append_child($topper);
...And I tried
Code: Select all
<?php
$echo "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>";
...The only I idea I have is to work with two files and fopen/fread/fwrite, but that seems a roundabout way...
Every example I see has the same approach, but shows the first line. (Note, I have to use dump_file or something similar.)
fyi, here is my generated xml file - I just need the first line to be added:
Code: Select all
<JSChart>
<dataset type="bar">
<data unit="Jan" value="5"/>
<data unit="Feb" value="7"/>
<data unit="Mar" value="10"/>
<data unit="Apr" value="12"/>
<data unit="May" value="14"/>
<data unit="Jun" value="0"/>
<data unit="Jul" value="0"/>
<data unit="Aug" value="0"/>
<data unit="Sep" value="0"/>
<data unit="Oct" value="0"/>
<data unit="Nov" value="0"/>
<data unit="Dec" value="0"/>
</dataset>
<optionset>
<option set="setBackgroundColor" value="'#efe'"/>
<option set="setAxisNameX" value="'Month'"/>
<option set="setAxisNameY" value="'GB'"/>
<option set="setSize" value="320,256"/>
<option set="setTitle" value="'Historical Data Back-up Trend'"/>
<option set="setTitleColor" value="'#5555AA'"/>
<option set="setTitleFontSize" value="10"/>
</optionset>
</JSChart> Code: Select all
<?php
header('Content-Type: text/xml');
$dom = domxml_new_doc('1.0');
$root = $dom->create_element("JSChart");
$root = $dom->append_child($root);
$nxt_element = $dom->create_element("dataset");
$nxt_element = $root->append_child($nxt_element);
$type_attr = $dom->create_attribute("type","bar");
$nxt_element->append_child($type_attr);
...
$dom->dump_file("/tmp/test.xml", false, true);
?>