DOMDOCUMENT.CREATEELEMENT(3) 1 DOMDOCUMENT.CREATEELEMENT(3)DOMDocument::createElement - Create new element node
SYNOPSIS
public DOMElement DOMDocument::createElement (string $name, [string $value])
DESCRIPTION
This function creates a new instance of class DOMElement. This node will not show up in the document unless it is inserted with (e.g.)
DOMNode.appendChild(3).
PARAMETERS
o $name
- The tag name of the element.
o $value
- The value of the element. By default, an empty element will be created. The value can also be set later with DOMElement::$node-
Value.
RETURN VALUES
Returns a new instance of class DOMElement or FALSE if an error occurred.
ERRORS /EXCEPTIONS
o DOM_INVALID_CHARACTER_ERR - Raised if $name contains an invalid character.
EXAMPLES
Example #1
Creating a new element and inserting it as root
<?php
$dom = 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)
$dom->appendChild($element);
echo $dom->saveXML();
?>
The above example will output:
<?xml version="1.0" encoding="utf-8"?>
<test>This is the root element!</test>
NOTES
Note
The $value will not be escaped. Use DOMDocument::createTextNode to create a text node with escaping support.
SEE ALSO
DOMNode::appendChild, DOMDocument::createAttribute, DOMDocument::createAttributeNS, DOMDocument::createCDATASection, DOMDocument::create-
Comment, DOMDocument::createDocumentFragment, DOMDocument::createElementNS, DOMDocument::createEntityReference, DOMDocument::createPro-
cessingInstruction, DOMDocument::createTextNode.
PHP Documentation Group DOMDOCUMENT.CREATEELEMENT(3)
Check Out this Related Man Page
SIMPLEXML_IMPORT_DOM(3) 1 SIMPLEXML_IMPORT_DOM(3)simplexml_import_dom - Get a SimpleXMLElementobject from a DOM node.SYNOPSIS
SimpleXMLElement simplexml_import_dom (DOMNode $node, [string $class_name = "SimpleXMLElement"])
DESCRIPTION
This function takes a node of a DOM document and makes it into a SimpleXML node. This new object can then be used as a native SimpleXML
element.
PARAMETERS
o $node
- A DOM Element node
o $class_name
- You may use this optional parameter so that simplexml_import_dom(3) will return an object of the specified class. That class
should extend the SimpleXMLElement class.
RETURN VALUES
Returns a SimpleXMLElement or FALSE on failure.
Warning
This function may return Boolean FALSE, but may also return a non-Boolean value which evaluates to FALSE. Please read the section on
Booleans for more information. Use the === operator for testing the return value of this function.
EXAMPLES
Example #1
Importing DOM
<?php
$dom = new DOMDocument;
$dom->loadXML('<books><book><title>blah</title></book></books>');
if (!$dom) {
echo 'Error while parsing the document';
exit;
}
$s = simplexml_import_dom($dom);
echo $s->book[0]->title;
?>
The above example will output:
blah
SEE ALSO dom_import_simplexml(3), "Basic SimpleXML usage".
PHP Documentation Group SIMPLEXML_IMPORT_DOM(3)
Hi, I need to parse a string, check if there are periods and strip the string.
For example i have the following domains and subdomains: mydomain.com, dev.mydomain.com
I need to strip all periods so i have a string without periods or domain extensions: mydomain, devmydomain.
I use this for... (12 Replies)
Hi,
I have large xml data file.I need to extract node and some tags in the node and after I need to create word document. my XMl data is look like as below
-<student>
<number>24</number>
<education>bachelor</bachelor>
<specialization>computers</specialization>
... (3 Replies)
hi everyone,
I written one script that search all xml files and create one xml file, but I need to remove some duplicate nodes by testing one tag element.
</Datainfo>
<data>
<test>22</test>
<info>sensor value</info>
<sensor>
<sensor value="23"... (0 Replies)
Hey i try to create empty text file with utf-8 encoding
without success
what is the right way to do this ?
tried with
touch test.txt
iconv -f UTF-8 -t UTF-8 test.txt
or
iconv -f latin1 -t UTF-8 test.txt (8 Replies)