tags:

views:

143

answers:

3
XML Parsing Error: no element found
Location: http://localhost/rss/
Line Number 1, Column 1:

However, when I paste the xml into http://validator.w3.org/feed/check.cgi , it say no formatting error.

FULL CODE AT BELOW:

index.php

<?php
    header("Content-Type: application/xml; charset=ISO-8859-1");


$details = '<?xml version="1.0" encoding="ISO-8859-1" ?>
      <rss version="2.0">
       <channel>
          <title>hehe</title>
          <link>http://www.google.com&lt;/link&gt;
          <description>gaga</description>
       </channel>
      </rss>
      ';
echo $details;

?>
A: 

Who is reporting the Parsing Error? I put the code on my machine and it worked as expected. Firefox asked to subscribe to the feed.

ingorichter
I run it in my localhost pc, firefox too... But it come out error.
i need help
A: 

You have to be really careful to ensure there are no line breaks or white space before the XML declaration. Even a single line break will cause problems.

Sohnee
A: 

Make sure you haven't got a stray BOM at the start of your PHP file. Some (stupid, broken) editors on Windows will drop a UTF-8-encoded BOM onto the start of a file when saving as UTF-8. This is pointless (as UTF-8 does not have byte order issues) and undesirable (as it will break compatibility with byte-oriented processing tools).

Since you are serving your output as ISO-8859-1, any UTF-8-encoded BOM at the start becomes the 8859-1 sequence . For XML this would be non-whitespace character data outside the root element, which isn't allowed.

If this is what's happening, fix it by saving your PHP file as ‘Western’ (cp1252) encoding, or look for a ‘UTF-8 without BOM’ encoding to save under.

bobince