PHP __construct() Function
PHP SimpleXML Reference Manual
Example
The function creates a new SimpleXMLElement object, then outputs the content of the body node:
Tove Jani Reminder Don't forget me this weekend! 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 to an XML document (if data_is_url is TRUE). |
| options |
Optional. Specifies additional Libxml parameters. Set by specifying the option as 1 or 0 (TRUE or FALSE, e.g. LIBXML_NOBLANKS(1)).
Possible values:
|
LIBXML_COMPACT - Activate optimized node configuration (can speed up the application)
LIBXML_DTDATTR - Set default DTD attributes
LIBXML_DTDLOAD - Load the external subset
LIBXML_DTDVALID - Validate DTD validity
LIBXML_NOBLANKS - Remove empty nodes
LIBXML_NOCDATA - Set CDATA as text nodes
LIBXML_NOEMPTYTAG - Expand empty tags (e.g.
to
), only valid in the DOMDocument->save() and DOMDocument->saveXML() functions
LIBXML_NOENT - Substitute entities
LIBXML_NOERROR - Do not show error reports
LIBXML_NONET - Stop network access when loading the document
LIBXML_NOWARNING - Do not show warning reports
LIBXML_NOXMLDECL - Drop the XML declaration when saving a document
LIBXML_NSCLEAN - Remove redundant namespace declarations
LIBXML_PARSEHUGE - Set the XML_PARSE_HUGE flag to relax any mandatory limits of the parser. This affects things such as the maximum document depth and text node size limits.
LIBXML_XINCLUDE - Use XInclude substitution
LIBXML_ERR_ERROR - Get recoverable errors
LIBXML_ERR_FATAL - Get fatal errors
LIBXML_ERR_NONE - Get no errors
LIBXML_ERR_WARNING - Get simple warnings
LIBXML_VERSION - Get the libxml version (e.g. 20605 or 20617)
LIBXML_DOTTED_VERSION - Get the dotted libxml version (e.g. 2.6.5 or 2.6.17)
| | *data_is_url* | Optional. If TRUE, indicates that *data* is the path or URL to an XML document rather than string data. Default is FALSE. | | *ns* | Optional. Specifies a namespace prefix or URI. | | *is_prefix* | Optional. Specifies a boolean. If *ns* is a prefix then TRUE, if *ns* is a URI then FALSE. Default is FALSE. |
Technical Details
| Return Value: |
Returns an object representing data . |
| PHP Version: |
5.0.1+ |
| PHP Changelog: |
PHP 5.1.2: Added options and data_is_url parameter was added. |
| PHP 5.2: Added ns and is_prefix parameter was added. |
|
More examples
Assume we have the following XML file note.xml :
Tove
Jani
Reminder
Don't forget me this weekend!
Example 1
Create a SimpleXMLElement object from a URL:
asXML ( ) ; ?>
Run Example »
PHP SimpleXML Reference Manual