DOMDocument::loadXML
PHP function
Edit on GitHub ✎
(PHP 5, PHP 7, PHP 8)
Load XML from a string
Description
DOMDocument::loadXML(string $source, int $options = 0): bool
Loads an XML document from a string.
Parameters
sourceThe string containing the XML.
optionsBitwise
ORof the libxml option constants.
Return Values
Success
Errors/Exceptions
Throws a ValueError if source is an empty string.
Changelog
| Version | Description |
|---|---|
| 8.3.0 | This function now has a tentative bool return type. |
| 8.0.0 | Passing an empty string as source now throws a ValueError; previously, an E_WARNING was raised and false was returned. |
| 8.0.0 | Calling this function statically will now throw an Error. Previously, an E_DEPRECATED was raised. |
Examples
Creating a Document
php
<?php
$doc = new DOMDocument();
$doc->loadXML('<root><node/></root>');
echo $doc->saveXML();
?>See Also
DOMDocument::loadDOMDocument::saveDOMDocument::saveXML