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
308
votes
34 answers

How to convert array to SimpleXML

How can I convert an array to a SimpleXML object in PHP?
Mike
232
votes
12 answers

Get value from SimpleXMLElement Object

I have something like this: $url = "http://ws.geonames.org/findNearbyPostalCodes?country=pl&placename="; $url .= rawurlencode($city[$i]); $xml = simplexml_load_file($url); echo $url."\n"; $cityCode[] = array( 'city' => $city[$i], 'lat' =>…
kubas
  • 2,321
  • 2
  • 14
  • 3
148
votes
10 answers

Accessing @attribute from SimpleXML

I am having a problem accessing the @attribute section of my SimpleXML object. When I var_dump the entire object, I get the correct output, and when I var_dump the rest of the object (the nested tags), I get the correct output, but when I follow…
benjy
  • 4,664
  • 7
  • 38
  • 43
108
votes
9 answers

'xmlParseEntityRef: no name' warnings while loading xml into a php file

I am reading an xml in php using simplexml_load_file. However while trying to load the xml it displays a list of warnings Warning: simplexml_load_file() [function.simplexml-load-file]:
Rajat Gupta
  • 25,853
  • 63
  • 179
  • 294
95
votes
4 answers

PHP simpleXML how to save the file in a formatted way?

I'm trying add some data to an existing XML file using PHP's SimpleXML. The problem is it adds all the data in a single line: blahblahblah ... And so on. All in a single line. How to introduce line…
user61734
  • 2,813
  • 5
  • 25
  • 18
92
votes
8 answers

SimpleXml to string

Is there any function that makes string from PHP SimpleXMLElement?
liysd
  • 4,413
  • 13
  • 35
  • 38
87
votes
7 answers

How to use XMLReader in PHP?

I have the following XML file, the file is rather large and i haven't been able to get simplexml to open and read the file so i'm trying XMLReader with no success in php
Shadi Almosri
  • 11,678
  • 16
  • 58
  • 80
82
votes
13 answers

PHP 7 simpleXML

I'm testing PHP7, and have a weird issue after a recent update. SimpleXML should be enabled by default, and my phpinfo page shows that it is available: However, the functions are not available:
user101289
  • 9,888
  • 15
  • 81
  • 148
81
votes
11 answers

Forcing a SimpleXML Object to a string, regardless of context

Let's say I have some XML like this This is title 1 The code below does what I want in that it outputs the title as a string $xml = simplexml_load_string($xmlstring); echo…
Mark Biek
  • 146,731
  • 54
  • 156
  • 201
81
votes
3 answers

Using SimpleXML to create an XML object from scratch

Is it possible to use PHP's SimpleXML functions to create an XML object from scratch? Looking through the function list, there's ways to import an existing XML string into an object that you can then manipulate, but if I just want to generate an…
dirtside
  • 8,144
  • 10
  • 42
  • 54
73
votes
5 answers

What's the difference between PHP's DOM and SimpleXML extensions?

I'm failing to comprehend why do we need 2 XML parsers in PHP. Can someone explain the difference between those two?
Stann
  • 13,518
  • 19
  • 65
  • 73
71
votes
11 answers

Error: "Input is not proper UTF-8, indicate encoding !" using PHP's simplexml_load_string

I'm getting the error: parser error : Input is not proper UTF-8, indicate encoding ! Bytes: 0xED 0x6E 0x2C 0x20 When trying to process an XML response using simplexml_load_string from a 3rd party source. The raw XML response does declare the content…
Camsoft
  • 11,718
  • 19
  • 83
  • 120
68
votes
7 answers

Unterminated entity reference in PHP

Here is my code: '); $products = $rss->addChild('products'); /// while($row = mysql_fetch_array($result)){ $product =…
mega6382
  • 9,211
  • 17
  • 48
  • 69
65
votes
7 answers

How check if a String is a Valid XML with-out Displaying a Warning in PHP

i was trying to check the validity of a string as xml using this simplexml_load_string()Docs function but it displays a lot of warning messages. How can I check whether a string is a valid XML without suppressing (@ at the beginning) the error and…
jspeshu
  • 1,211
  • 3
  • 12
  • 20
65
votes
17 answers

php SimpleXML check if a child exists

A->b->c might exist but c might not exist. How do I check it?
An employee
  • 6,188
  • 9
  • 33
  • 43
1
2 3
99 100