PHP __construct()Functions
PHP SimpleXML Reference Manual
Examples
The function creates a new SimpleXMLElement object, then outputs the content of the body node:
$note=<<<XML
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
XML;
$xml=new SimpleXMLElement($note);
echo $xml->body;
Run example »
Definition and Usage
The __construct() function creates a new SimpleXMLElement object.
Syntax
__construct(data,options,data_is_url,ns,is_prefix);
| Parameters | Description |
|---|---|
| data | Required. A well-formed XML string or the path or URL of an XML document (if data_is_url is TRUE). |
| options | Optional. Specifies additional Libxml parameters. Set by specifying options as 1 or 0 (TRUE or FALSE, e.g., LIBXML_NOBLANKS(1)). Possible values:
|
| data_is_url | Optional. If TRUE, it indicates datais the path or URL of the XML document, not string data. Default is FALSE. |
| ns | Optional. Specifies the namespace prefix or URI. |
| is_prefix | Optional. Specifies a boolean value. Ifnsis a prefix then TRUE, ifnsis a URI then FALSE. Default is FALSE. |
Technical Details
| Return Values: | Returns adataSimpleXMLElement object representing the ... |
|---|---|
| PHP Version: | 5.0.1+ |
| PHP Changelog: | PHP 5.1.2: Added theoptionsanddata_is_urlparameter. PHP 5.2: Addednsandis_prefixparameter. |
More Examples
Assume we have the following XML filenote.xml :
<?xml version="1.0" encoding="UTF-8"?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
Example 1
Create a SimpleXMLElement object from a URL:
$xml=new SimpleXMLElement("note.xml",0,TRUE);
echo $xml->asXML();
Run example »
Other Extensions