CodeIgniter Forums
How do I output XML in the view? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: How do I output XML in the view? (/showthread.php?tid=12753)



How do I output XML in the view? - El Forum - 10-30-2008

[eluser]RedLeader[/eluser]
Hello everyone,

Sorry for what appears to be a very noob question but I don't know if I am outputting XML to the view properly.

When I try to do it I put the following in my view file called "response_view.php":
Code:
<?php echo '<?xml version="1.0" encoding="UTF-8"?>'; ?>
<response>
    <type>&lt;?php echo $type ?&gt;</type>
    <message>&lt;?php echo $message ?&gt;</message>
</response>

Is that good enough?

Thanks for any help you can offer!


How do I output XML in the view? - El Forum - 10-30-2008

[eluser]GSV Sleeper Service[/eluser]
you may want to add a content-type header before you send any output.
Code:
header('Content-type: text/xml');
you'll probably want a DTD if you want well formed, valid XML


How do I output XML in the view? - El Forum - 10-30-2008

[eluser]RedLeader[/eluser]
Brilliant - thanks!


How do I output XML in the view? - El Forum - 01-24-2010

[eluser]Eric Cope[/eluser]
anyone know why you have to echo the &lt;?xml ... ?&gt; line?


How do I output XML in the view? - El Forum - 01-25-2010

[eluser]JHackamack[/eluser]
The XML heading tag is similar to the <DOCTYPE tag you use at the top of HTML. It tells the client the encoding and version of xml to look against. Some clients require that it be in, some do not, it all depends on your requirement. Just remember if you have a validation script that checks for validation and don't include the &lt;?xml then it would most likely fail.


How do I output XML in the view? - El Forum - 01-25-2010

[eluser]Eric Cope[/eluser]
I think I was unclear. I understand why that line needs to be sent via output. However, if you just place it in your view file, you get an T_STRING error. If you echo it out, it works just fine.


How do I output XML in the view? - El Forum - 01-25-2010

[eluser]JHackamack[/eluser]
Its because of the &lt;?xml rather than &lt;?php PHP tries to do processing on that line.


How do I output XML in the view? - El Forum - 01-25-2010

[eluser]Eric Cope[/eluser]
I figured that was the problem. Thanks for the response!


How do I output XML in the view? - El Forum - 01-25-2010

[eluser]HdotNET[/eluser]
Output class

See the output class for more info on how to set headers..

Its possible that in future versions of CI, output headers will be cached along with view data, but only if you use the proper CI method rather than the raw php header() function.