DomDocument->create_element_ns
DomDocument->create_element_ns — 関連する名前空間を持つ新規要素ノードを作成する
説明
domelement DomDocument->create_element_ns ( string uri, string name [, string prefix] )この関数は
DomElement
クラスの新規インスタンスを返します。
要素のタグ名は渡されたパラメータ name の値です。
名前空間の URI は渡されたパラメータ uri
の値です。文章のルートノードで同じ名前空間が URI
がすでに宣言されている場合、その接頭辞が使用されます。
そうでない場合、オプションパラメータ prefix
で与えられた接頭辞、もしくはランダムに設定された接頭辞が使用されます。
このノードは、domnode_append_child()
などで挿入されない限り、ドキュメント内に現われません。
エラーが発生した場合、戻り値は FALSE です。
domdocument_create_element_ns(), domnode_add_namespace(), domnode_set_namespace(), domnode_append_child(), domdocument_create_text(), domdocument_create_comment(), domdocument_create_attribute(), domdocument_create_processing_instruction(), domdocument_create_entity_reference(), domnode_insert_before() も参照ください。
DOMDocument->createElementNS()
DOMDocument->createElementNS() — 関連付けられた名前空間に新しい要素を作成する
説明
class DOMDocument {DOMElement createElementNS ( string namespaceURI, string qualifiedName [, string value] )
} この関数は、関連付けられた名前空間に新しい要素を作成します。 このノードは、DOMNode->appendChild() などで 挿入されない限り、ドキュメント内に現われません。
パラメータ
- namespaceURI
-
名前空間の URI。
- qualifiedName
-
要素名を、prefix:tagname
のような形式で指定する。
- value
-
要素の値。デフォルトでは、空の要素が作成されます。
その後に DOMElement->nodeValue で
値を設定することも可能です。
返り値
新しいDOMElement
、
あるいはエラーが発生した場合には FALSE を返します。
エラー / 例外
- DOM_INVALID_CHARACTER_ERR
-
qualifiedName が無効な文字を含んでいる場合に発生します。
- DOM_NAMESPACE_ERR
-
qualifiedName が無効な名前である場合に発生します。
例
例 488. 新しい要素を作成し、ルートとして挿入する
<?php
$dom = new DOMDocument('1.0', 'iso-8859-1');
$element = $dom->createElementNS('http://www.example.com/XFoo', 'xfoo:test', 'This is the root element!');
// 新しい要素をルート (ドキュメントの子要素) として挿入する
$dom->appendChild($element);
echo $dom->saveXML();
?>
上の例の出力は以下となります。<?xml version="1.0" encoding="iso-8859-1" ?>
<xfoo:test xmlns:xfoo="http://www.example.com/XFoo">This is the root element!</xfoo:test>
参考
- DomDocument->create_element_nsのページへのリンク