0

I have an url return an XML page result. When I use this command:

print_r(file($url));

Its done, but when I use command:

$doc =  load($url);

after that I :

print_r($doc);

it out. Its print_r out nothing. I'm quite new in work with XML in PHP someone give advise, please! Thank you for your attention!

3
  • What is load() supposed to be doing? Commented Nov 16, 2009 at 4:37
  • +1 deceze, give us the revelant code part ... Commented Nov 16, 2009 at 4:38
  • 1
    It might only seem like nothing is printed out. As far as I understand, you are doing something with XML - therefore I assume that the tags are not escaped and thus interpreted as invalid HTML tags by the browser. As a result, nothing is displayed. You could check this by viewing the source of the page... Commented Nov 16, 2009 at 4:46

3 Answers 3

1

I am not really sure what you trying to do but for parsing an xml file in PHP there two main ways: DOM

$doc = new DOMDocument();
$doc->loadXML(file_get_contents($url));

SimpleXML

$xml = new SimpleXMLElement(file_get_contents($xmlstr));

file_get_contents Reads entire file into a string

Sign up to request clarification or add additional context in comments.

2 Comments

I'm using simplexml_load_file and get the same result like you suggest RageZ. But the result have many nested SimpleXMLElement Object children. To deal with this I have to waste a lot of time and I'm in hurry now! :D
@gacon: you should use xpath to get only the data you need.
0

@deceze and RageZ: I'm using load() to get its attribute like this

$url = 'web address return an XML result';
$xml = load($url);
$node1 = $xml->getElmentsByTagName('tagname');
$value = $node1->getAttribute('attribute1');

But I have an error $xml is not an object and I check out by print_r and I get nothing but with print_r(file($url)) its print out an array as I expect! @Franz: May be I get an error tag in XML file but I could not fixed this just work with the result!

2 Comments

Etiquette is to update your question if you have more info to add.
AFAIK load() is not a PHP function. So again, what does it do? Are you sure it does anything?
0

You could also unserialize the xml into a php array and use print_r(array). Take a look here: http://articles.sitepoint.com/article/xml-php-pear-xml_serializer/3#

You will need a PEAR package for this

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.