Current Location: Home> Function Categories> __construct

__construct

Creates a new SimpleXMLElement object.
Name:__construct
Category:Uncategorized
Programming Language:php
One-line Description:Creates a new SimpleXMLElement object.

Definition and usage

The __construct() function is used to create a new SimpleXMLElement object.

Example

Example 1

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

Example 2

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

grammar

 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:

  • LIBXML_COMPACT - Activate node allocation optimization (may accelerate application)
  • LIBXML_DTDATTR - Set the default DTD attribute
  • LIBXML_DTDLOAD - Loading external subsets
  • LIBXML_DTDVALID - Verify using DTD
  • LIBXML_NOBLANKS - Remove blank nodes
  • LIBXML_NOCDATA - Merge CDATA into text nodes
  • LIBXML_NOEMPTYTAG - Extended empty tags (e.g. <br/> to <br></br>)
    (Available only in the DOMDocument->save() and DOMDocument->saveXML() functions)
  • LIBXML_NOENT - Replace entity
  • LIBXML_NOERROR - No error report displayed
  • LIBXML_NONET - Disable network access when loading a document
  • LIBXML_NOWARNING - Warning report not displayed
  • LIBXML_NOXMLDECL - Omit XML declaration when saving a document
  • LIBXML_NSCLEAN - Remove redundant namespace declarations
  • LIBXML_PARSEHUGE - Set the XML_PARSE_HUGE flag to relax the hard-coded limits of the parser.
    (This affects the maximum depth of the document and the limits of the text node size)
  • LIBXML_XINCLUDE - Implement XInclude replacement
  • LIBXML_ERR_ERROR - Get recoverable errors
  • LIBXML_ERR_FATAL - Get a fatal error
  • LIBXML_ERR_NONE - Get No Errors
  • LIBXML_ERR_WARNING - Get a simple warning
  • LIBXML_VERSION - Get the libxml version (for example 20605 or 20617)
  • LIBXML_DOTTED_VERSION - Get the dotted version of libxml (for example, 2.6.5 or 2.6.17)
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.

Similar Functions
Popular Articles