The __construct()
function is used to create a new SimpleXMLElement object.
Create a SimpleXMLElement object from a string:
<?php $note = <<< XML <note> <to>George</to> <from>John</from> <heading>Reminder</heading> <body>Do not forget the meeting!</body> </note> XML ; $xml = new SimpleXMLElement ( $note ) ; echo $xml -> asXML ( ) ; ?>
Run the instance
Suppose we have the following XML file " note.xml ":
<? xml version = "1.0" encoding = "UTF-8" ?> < note > < to > George </ to > < from > John </ from > < heading > Reminder </ heading > < body > Don't forget me this weekend! </ body > </ note >
Create a SimpleXMLElement object from the URL:
<?php $xml = new SimpleXMLElement ( "note.xml" , 0 , TRUE ) ; echo $xml -> asXML ( ) ; ?>
Run the instance
SimpleXMLElement :: __construct ( data , options , data_is_url , ns , is_prefix )
parameter | describe |
---|---|
data |
Required. Specifies a well-formed XML string. If data_is_url is TRUE, specify the path or URL of the XML document. |
options |
Optional. Specify additional Libxml parameters. Set by specifying options and 1 or 0 (TRUE or FALSE, such as LIBXML_NOBLANKS(1)). Possible values include:
|
data_is_url |
Optional. TRUE Specifies that data is the path/url of the XML document rather than string data. The default is FALSE. |
ns | Optional. Specifies a namespace prefix or URI. |
is_prefix |
Optional. Specifies a boolean value. TRUE if ns is a prefix, and FALSE if ns is a URI. The default is FALSE. |