开发者

xml tree with php + header

when i open this page with FireFox or Opera all looks fine (show xml tree), but when open with IE8 or Chrome I get this xml text in one line. Why? How fix?

<?php
    $xml = '
    <catalog>
        <book id="bk101">
            <author>Gambardella, Matthew</author>
            <title>XML Developer Guide</title>
        </book>
        <book id="bk102">
            <author>Ralls, Kim</author>
            <title>Midnight Rain</title>
        </book>
    </catalog>';

    header("Content-type: text/xml;charset:UTF-8");
    echo '<?xml version="1.0" encoding="UTF-8"?>';
    echo $xml;
  开发者_Go百科  die;
    ?>


Internet Explorer and Chrome doesn't have fancy XML rendering built in, whereas Firefox and Opera does.

You can see if they actually do get the documents correctly by pressing viewing the source of the pages. (Ctrl-U in Chrome, Alt-VC in Internet Explorer)

If you want to rely on an XML document rendering a specific way, you'll have to use an XSL/XSLT to format it correctly.

For Chrome there are also a number of extensions you could try, which aim to add what you seek:

  • XML Viewer
  • XML Tree
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜