How can I output XML stored string from controller or view in Codeigniter

怎甘沉沦 提交于 2021-02-08 11:45:46

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!