Results 1 to 2 of 2

Thread: Help outputing xml in correct format using php

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    Help outputing xml in correct format using php

    Hi all. i try to output xml data using the following php code but
    when i run the php script i don't get the xml output in correct format.




    PHP Code:
    <?
    echo"  <playing>\n";
    echo"   <artist>Kambiz</artist> \n";
    echo"   <song>Shookolat</song> \n";
    echo"   <image>http://www.somesite.com/song_images/kambiz.jpg</image> \n";
    echo"   <rating>2.44444</rating> \n";
    echo"   <songid>3003</songid> \n";
    echo"   </playing>\n";

    ?>

    I want the xml to be outputed as shown in this pic:


    correct output format:
    Code:
    - <playing>
      <artist>Kambiz</artist> 
      <song>Shookolat</song> 
      <image>http://www.somesite.com/static/artists/shakila.jpg</image> 
      <rating>2.44444</rating> 
      <songid>3003</songid> 
      </playing>
    http://allyoucanupload.webshots.com/...91865848610011


    Not correct xml format:

    Code:
    Kambiz Shookolat http://www.somesite.com/song_images/kambiz.jpg 2.44444 3003
    http://aycu13.webshots.com/image/274...6588372_rs.jpg
    could any one tell me how to output the xml data in the following format.Thanks
    Last edited by tony007; Sep 27th, 2007 at 08:53 PM.

  2. #2
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Help outputing xml in correct format using php

    Have you sent a Content-type header?
    This is required in order to signal to the user agent that the document is of an XML type and should be parsed as such.

    PHP Code:
    header('Content-type: text/xml; charset=utf-8'); 
    Also, you should never use echo() to output large chunks of content like that. In fact there is simply no need to use any PHP here.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width