Overview
KB
Technical FAQ
PHP Manual
CSS2 Manual
HTML Manual
JS Guide
JS Reference
PhpDock Manual
Nu-Coder Manual
PhpExpress Manual
PHP Joomla
Development
Learn PHP
 
<DOMDocument::loadHTMLFileDOMDocument::normalizeDocument>
^DOMDocumentLast updated: Mon, 26 Oct 2026

DOMDocument::loadXML

(PHP 5, PHP 7, PHP 8)

DOMDocument::loadXML — Load XML from a string

Description

public function DOMDocument::loadXML(string $source, int $options = 0): bool

Loads an XML document from a string.

Parameters

source

The string containing the XML.

options

Bitwise OR of the libxml option constants.

Return Values

Returns true on success or false on failure.

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

Example #1 Creating a Document

<?php
$doc = new DOMDocument();
$doc->loadXML('<root><node/></root>');
echo $doc->saveXML();
?>

See Also


<DOMDocument::loadHTMLFileDOMDocument::normalizeDocument>
^DOMDocumentLast updated: Mon, 26 Oct 2026