Loading XML data into simplexml

suggest change

Loading from string

Use simplexml_load_string to create a SimpleXMLElement from a string:

$xmlString = "<?xml version='1.0' encoding='UTF-8'?>";
$xml = simplexml_load_string($xmlString) or die("Error: Cannot create object");

Note that or not || must be used here because the precedence of or is higher than =. The code after or will only be executed if $xml finally resolves to false.

Loading from file

Use simplexml_load_file to load XML data from a file or a URL:

$xml = simplexml_load_string("filePath.xml");

$xml = simplexml_load_string("https://example.com/doc.xml");

The URL can be of any schemes that PHP supports, or custom stream wrappers.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


SimplXML:
* Loading XML data into simplexml

Table Of Contents
2 Arrays
4 Types
10 Cookies
14 JSON
15 SOAP
17 cURL
19 XML
21 Traits
35 UTF-8
36 URLs
38 PHPDoc
41 Loops
44 Closur
72 YAML
77 Cache
78 Streams
81 PDO
82 SQLite3
83 Sockets
87 MongoDB
93 IMAP
94 Redis
95 Imagick
96 SimplXML
102 APCu
108 PSR