(PHP 5, PHP 7, PHP 8) DOMDocument::createElement — Create new element node Descriptionpublic DOMDocument::createElement(string ParameterslocalName The tag name of the element. value The value of the element. By default, an empty element will be created. The value can also be set later with DOMElement::$nodeValue. The value is used verbatim except that the < and > entity references will escaped. Note that & has to be manually escaped; otherwise it is regarded as starting an entity reference. Also " won't be escaped. Return Values Returns a new instance of class
DOMElement or Errors/ExceptionsDOM_INVALID_CHARACTER_ERR Raised if ExamplesExample #1 Creating a new element and inserting it as root
= new DOMDocument('1.0', 'utf-8');$element = $dom->createElement('test', 'This is the root element!');// We insert the new element as root (child of the document) The above example will output: <?xml version="1.0" encoding="utf-8"?> <test>This is the root element!</test> Example #2 Passing text containing an unescaped & as
The above example will output something similar to: Warning: DOMDocument::createElement(): unterminated entity reference you in /in/BjTCg on line 4 <?xml version="1.0" encoding="utf-8"?> <foo/> See Also
mikek dot nospam at nospam dot muonics dot com ¶ 15 years ago
XDOMDocument extends DOMDocument { sergsokolenko at gmail dot com ¶ 15 years ago
funkathustra ¶ 10 years ago
yasindagli at gmail dot com ¶ 13 years ago
$attributes != NULL ) estill at gvtc dot com ¶ 15 years ago
$doc->saveXML(); lars dot c dot magnusson at gmail dot com ¶ 11 years ago
tschmieder at bitworks dot de ¶ 7 years ago
chris AT cmbuckley DOT co DOT uk ¶ 13 years ago
= new DOMDocument('1.0', 'utf-8'); dignat at yahoo dot com ¶ 4 years ago
|