问题
I want to show XML content header type output from view but getting an error. Below is the code that I am putting into my view.
<?php header("Content-Type: text/xml;charset=iso-8859-1"); ?>
<?php '<?xml version="1.0" encoding="UTF-8" ?>' ?>
<urlset xmlns="">
<url>
<loc>Something</loc>
<priority>1.0</priority>
</url>
<!-- My code is looking quite different, but the principle is similar -->
<url>
<loc>Somthing</loc>
<priority>0.5</priority>
</url>
</urlset>
And that is the error that I am getting from it.
Click to view Error Message
回答1:
Codeigniter has an easier way to output different kinds of content types (XML, JSON...), give it a try:
Remove the code you created, inside your controller method put this code at the end instead:
$this->output
->set_content_type('text/xml')
->set_output('your xml file or XML content');
It is important to now that, if there is any blank line before the code above your browser might interpret the output differently of XML, so when you get the result, check for a blank line in the output page (if there is no, you are okay).
来源:https://stackoverflow.com/questions/53314457/how-can-i-output-xml-stored-string-from-controller-or-view-in-codeigniter