2

When I access the page of the following PHP code in IE, IE produces the error, "Internet Explorer does not support feeds with DTDs. This feed contains a DTD (Document Type Definition). ... ... DTDs are used to define a structure of a webpage. Internet Explorer does not support DTDs in feeds."

<?php 
header('Content-Type: text/xml');
echo '<?xml version="1.0" encoding="UTF-8" ?>';
?>          
<!DOCTYPE doctypeName [
   <!ENTITY nbsp "&#160;">
]>                  
<rss version="2.0">
<channel>
    <title>Sample Feed</title>
    <link>http://google.com</link>
    <description>This is a test</description>   
        <item>
            <title>Item</title>
            <description>This is the item.&nbsp;&nbsp;</description>
        </item>
</channel>      
</rss>

I suspect this part is the problem:

<!DOCTYPE doctypeName [
   <!ENTITY nbsp "&#160;">
]>  

But if I remove it, I get this error instead:

Reference to undefined entity 'nbsp'. Line: 10 Character: 36

This is the item.  

So it is necessary to allow &nbsp; in the description tag.

Any ideas?

4

1 に答える 1

2

&nbsp; is not valid XML. Using a DTD to make it valid is a terrible workaround.

If you need it in your content, that content is really HTML; in that case, you should either

  • wrap it in CDATA tags or
  • escape the ampersands into &amp;.

This question gives an overview over which method is better. Quentin's answer also contains another solution, using a XML library to create the markup. It may be overkill for your specific example, but it usually the best way to go.

于 2012-10-18T00:28:34.557 に答える