Questions tagged [simplexml]

A PHP extension shipped with the main source tree. The SimpleXML extension provides a very simple and easily usable toolset to convert XML to an object that can be processed with normal property selectors and array iterators. For the Java "Simple" XML framework, please use the [simple-framework] tag.

The SimpleXML extension provides a simple toolset to convert XML to an object that can be processed with normal property selectors and array iterators.

Once an XML document is converted, the object obtained will reference the root element of the document. The object's properties will reflect the child nodes and uses the same name as the nodes. This principle works recursively across the document.

3932 questions
28
votes
6 answers

simplexml error handling php

I am using the following code: function GetTwitterAvatar($username){ $xml = simplexml_load_file("http://twitter.com/users/".$username.".xml"); $imgurl = $xml->profile_image_url; return $imgurl; } function GetTwitterAPILimit($username,…
mrpatg
  • 10,001
  • 42
  • 110
  • 169
28
votes
7 answers

Best way to process large XML in PHP

I have to parse large XML files in php, one of them is 6.5 MB and they could be even bigger. The SimpleXML extension as I've read, loads the entire file into an object, which may not be very efficient. In your experience, what would be the best way?
Petruza
  • 11,744
  • 25
  • 84
  • 136
24
votes
2 answers

Call to undefined function simplexml_load_file()

I have php 7.0 running on my ubuntu server. php -m command says: [PHP…
Sneha Maheshwari
  • 419
  • 1
  • 3
  • 7
24
votes
2 answers

How can I set text value of SimpleXmlElement without using its parent?

I want to set text of some node found by xpath() text stuff code XML ); // I want to set text of some node found by xpath // Let's…
Kamil Szot
  • 17,436
  • 6
  • 62
  • 65
24
votes
1 answer

Get root node of XML doc using simplexml

Using simplexml_load_string() how do I get "ForgotPassword" from the following XML? 1.0 username
John Conde
  • 217,595
  • 99
  • 455
  • 496
23
votes
5 answers

Getting SimpleXMLElement to include the encoding in output

This: $XML = new SimpleXMLElement(""); echo($XML->asXML()); ...outputs this: But I want it to output the encoding, too: Is there some way to tell SimpleXMLElement…
dirtside
  • 8,144
  • 10
  • 42
  • 54
23
votes
4 answers

Quickly convert simpleXMLObject to STDClass?

Does anybody know a quick way to convert a SimpleXMLElement to a normal STDClass object, without iterating through each branch manually? I would feel better working with a normal object after fetching the data.
Pekka
  • 442,112
  • 142
  • 972
  • 1,088
23
votes
5 answers

SimpleXML Attributes to Array

Is there any more elegant way to escape SimpleXML attributes to an array? $result = $xml->xpath( $xpath ); $element = $result[ 0 ]; $attributes = (array) $element->attributes(); $attributes = $attributes[ '@attributes' ]; I don't really want to…
mseancole
  • 1,662
  • 4
  • 16
  • 26
22
votes
3 answers

PHP: Whats's the difference between the SimpleXMLElement() class and SimpleXML_load_string()?

I've seen alot of coders implement SimpleXML_load_string() instead of the SimpleXMLElement() class. Are there any benefits to using the former over the latter? I've read the PHP manual on simplexml. I couldn't manage to get a grasp on what it is.…
VicePrez
  • 540
  • 1
  • 8
  • 17
22
votes
2 answers

Using SimpleXML to read RSS feed

I am using PHP and simpleXML to read the following rss feed: http://feeds.bbci.co.uk/news/england/rss.xml I can get most of the information I want like so: $rss = simplexml_load_file('http://feeds.bbci.co.uk/news/england/rss.xml'); echo '

'.…

geoffs3310
  • 13,640
  • 23
  • 64
  • 85
22
votes
2 answers

SimpleXML Reading node with a hyphenated name

I have the following XML:
Mark Baker
  • 209,507
  • 32
  • 346
  • 385
22
votes
2 answers

SimpleXML - "Node no longer exists"

I'm trying to get the video data from this youtube playlist feed and add the interesting data to an array and use that later, but as you can see from the feed some videolinks are "dead" and that results in problems for my code. The error I get is…
Andreas Norman
  • 323
  • 1
  • 2
  • 5
22
votes
3 answers

Access an element's parent with PHP's SimpleXML?

I'm iterating through a set of SimpleXML objects, and I can't figure out how to access each object's parent node. Here's what I want: $divs = simplexml->xpath("//div"); foreach ($divs as $div) { $parent_div = $div->get_parent_node(); // Sadly,…
thisismyname
  • 543
  • 2
  • 5
  • 10
22
votes
5 answers

Remove namespace from XML using PHP

I have an XML document that looks like this: ... I am parsing the information using SimpleXML in PHP. I…
jchimpo
  • 245
  • 1
  • 3
  • 7
21
votes
4 answers

Can simplexml be used to rifle through html?

I would like to grab data from a table without using regular expressions. I've enjoyed using simplexml for parsing RSS feeds and would like to know if it can be used to grab a table from another page. Eg. Grab the page with curl or simply…
chris
  • 2,913
  • 4
  • 43
  • 48