Change language

PHP SimpleXMLElement :: __ construct () function

The __construct() function - it is a built-in function in PHP that is used to create a new SimpleXMLElement object for XML.Syntax:
SimpleXMLElement::__ construct ($data, $options, $data_is_url, $namespace, $is_prefix) 
Parameters:This function takes five parameters as above and described below:
  • $data:This is a required parameter. It specifies a well-formed XML string or the path or URL of an XML document file if $data_is_url is TRUE.
  • $options:This is an optional parameter. It defines additional parameters for Libxml. Set by specifying an option and 1 or 0
  • $data_is_url:this is an optional parameter. The default is False. If the value of this parameter - True, this means the data is the path / URL to the XML document file instead of a string.
  • $namespace:This is an optional parameter. Specifies the URI or namespace prefix.
  • $is_prefix:This is an optional Boolean parameter. It specifies True if ns - prefix, and False if ns - URI. The default is invalid.
Return Value:returns a SimpleXMLElement object that represents structured XML dataNote. This feature is available for PHP 5.0.1 and later.example  
// Load XML document into $user $user = < < < XML < user >
< username > user123 < / username >
< name > firstname lastname < / name >
 + 91-XXXXXXXXXX < / phone >
< detail > I am John Doe. Live in Kolkata, India. < / detail >
< / user >
XML;  
// Create a new SimpleXMLElement
// object from $user $xml = new SimpleXMLElement ( $user );  
// Print in XML format echo $xml -> asXML();  
?>
Output:
user123 firstname lastname + 91-XXXXXXXXXX I am John Doe. Live in Kolkata, India. 
Browser output as source:
Example:load an XML document from a file or URL.sample.xml xml version = "1.0" ?> < user > < username > user123 < / username > < name > firstname lastname < / name > < phone > + XX-XXXXXXXXXX < / phone > < detail > I am John Doe. Live in Kolkata, India. < / detail > < / user > index.php  
// Load the XML document from sample.xml to $user
// and create a new SimpleXMLElement object $xml = new SimpleXMLElement ( "sample.xml" , 0, TRUE);  
// Print data as XML echo $xml -> asXML();  
?>
Output:
user123 firstname lastname + 91-XXXXXXXXXX I am John Doe. Live in Kolkata, India. 
Browser output as source:
Possible values ​​for $option:
  • LIBXML_COMPACT - optimization of node allocation is activated
  • LIBXML_DTDATTR - this option sets the default DTD attributes
  • LIBXML_DTDLOAD - external subset loading
  • LIBXML_DTDVALID - validating XML document with DTD
  • LIBXML_DOTTED_VERSION - get the split point libxml version
  • LIBXML_ERR_ERROR - get errors (correctable)
  • LIBXML_ERR_FATAL - get errors (fatal)
  • LIBXML_ERR_NONE - Get error free
  • LIBXML_ERR_WARNING - receive alerts (simple)
  • LIBXML_NOBLANKS - remove all empty nodes in the XML document
  • LIBXML_NOCDATA - merge new CDATA as text nodes
  • LIBXML_NOEMPTYTAG - expand empty tags
  • LIBXML_NOENT - Replace entities in XML document
  • LIBXML_NOERROR - limit error message
  • LIBXML_NONET - disables network access when loading XML documents
  • LIBXML_NOWARNING - limits warnings
  • LIBXML_NOXMLDECL - removes XML declaration when saving document
  • LIBXML_NSCLEAN - removes all redundant namespace declarations
  • LIBXML_PARSEHUGE - sets the XML_PARSE_HUGE flag, which removes any hard-coded constraints from the parser, again affecting constraints such as text node size and maximum document depth
  • LIBXML_XINCLUDE - replacing XInclude aggregates
  • LIBXML_VERSION - get an integer version of LIBXML.
Link: https://www.php.net/manual/en/simplexmlelement.construct.php

Shop

Best laptop for Sims 4

$

Best laptop for Zoom

$499

Best laptop for Minecraft

$590

Best laptop for engineering student

$

Best laptop for development

$

Best laptop for Cricut Maker

$

Best laptop for hacking

$890

Best laptop for Machine Learning

$950

Latest questions

NUMPYNUMPY

psycopg2: insert multiple rows with one query

12 answers

NUMPYNUMPY

How to convert Nonetype to int or string?

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Javascript Error: IPython is not defined in JupyterLab

12 answers

Wiki

Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | cv2.circle () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method