开发者

getting xml data as is(with tags, attributes and values) with php

Hello im struggling with a problem. I have an url that contains xml data... when i'm using file_get_contents($url) or fopen($url,'r') it gives me only values: Consider the 开发者_StackOverflow社区xml:

<tag1 attrName="something">
    <tag2>some Value</tag2>
    <tag2>some Other Value</tag2>
    ...
    ...
</tag1>

what i get: some Value, some Other Value

But i need to get whole xml (with tags and attributes and its' values) and parse it with my own way because there's a restriction that i'm not allowed to use php 5.x practices.I mean i cant use any parser.. It shouldnt be so hard to get xml data as is.. should it??


what i get: some Value, some Other Value

Nope - my suspicion is that that is what you see in your browser, because it is swallowing all <tags>.

The XML source code will be there after a file_get_contents() operation.


You are using file_get_contents() which states

This function is similar to file(), except that file_get_contents() returns the file in a string, starting at the specified offset up to maxlen bytes. On failure, file_get_contents() will return FALSE.

Press Ctrl+u to see the source code in any of the major browsers(except IE where its F12 in IE9). I am sure that your code will be there. Your browser wont display the tags that's all.

The other longer(but better way) to display an XML file from your php file is to pass the content type as text/xml. Use the following way

<?php 
header("Content-Type: text/xml");//SHOULD come before any output


// dynamically generate and output your xml here 
?> 
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜