dongyuan1870 2011-04-19 13:42
浏览 41
已采纳

如何从PHP输出XML字符串

I'm taking an XML string and editing it in PHP to finally output the edited XML string when the PHP file is accessed. I've been trying both echo and print to output the XML document, but it's only printing the data within the innermost tags. I want this to function as if you loaded an XML document directly such as test.com/example.xml. Instead it's only printing out part of the string instead of the whole thing. The print statement is below. Any advice?

print <kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:kml="http://www.opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom">

<Document> <Style id="undecorated_style"> <BalloonStyle> <displayMode>undecorated</displayMode> </BalloonStyle> </Style>

<Placemark>
    <name>Relative Marker Example</name>
    <description><![CDATA[
    <div style="position: absolute; width: 100px; height: 100px; left: -50px; top: -50px"><img width="100px" height="100px" src="http://argonapps.gatech.edu/examples/FrameMarkerThin_005.png"/></div>
    ]]>
    </description>
    <balloonVisibility>1</balloonVisibility>
    <Marker>
        <markerType>framesimpleid</markerType>
        <markerId>-1</markerId> <!-- integer value (-1 means follow any marker of markerType) -->
        <locationMode>relative</locationMode> <!-- default (ignore), relative (update location), fixed (update camera) -->
        <orientationMode>fixed</orientationMode>
        <scale>
            <x>0.076</x> <!-- test marker is 0.038 meters -->
            <y>0.076</y>
            <z>0.076</z>
        </scale>
    </Marker>
    <styleUrl>#undecorated_style</styleUrl>
</Placemark>

';

Opening the file in a browser shows only:

Relative Marker Example ]]> 1 framesimpleid -1 relative fixed 0.076 0.076 0.076 #undecorated_style

instead of simply the xml.

  • 写回答

3条回答 默认 最新

  • doudaotui4297 2011-04-19 13:43
    关注

    Before you print, add content type header.

    Either

    header('Content-type: text/xml');
    

    or more proper for KML

    header('Content-type: application/vnd.google-earth.kml+xml');
    

    If you want to view it in the browser as source, read this: http://www.w3schools.com/xml/xml_view.asp

    You can also force it to be displayed as text, by adding

     header('Content-type: text/plain');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测