Welcome Guest, Not a member yet? Register   Sign In
How do I output XML in the view?
#1

[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!
#2

[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
#3

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

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

[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.
#6

[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.
#7

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

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

[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.




Theme © iAndrew 2016 - Forum software by © MyBB