From 4677bf9a18a3080300a159114db0c445582b320b Mon Sep 17 00:00:00 2001 From: Mehdi Achour Date: Sat, 30 Dec 2006 02:50:59 +0000 Subject: [PATCH] Document DOMDocumentFragment->appendXML() and DOMDocument->registerNodeClass(), our 2 non-DOM-standard-but-kicks-axx methods git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@226020 c90b9560-bf6c-de11-be94-00142212c4b1 --- .../dom-domdocument-registernodeclass.xml | 108 ++++++++++++++++-- .../dom-domdocumentfragment-appendxml.xml | 93 ++++----------- reference/dom/reference.xml | 22 +++- 3 files changed, 145 insertions(+), 78 deletions(-) diff --git a/reference/dom/functions/dom-domdocument-registernodeclass.xml b/reference/dom/functions/dom-domdocument-registernodeclass.xml index 0a395b90df..37162a587d 100644 --- a/reference/dom/functions/dom-domdocument-registernodeclass.xml +++ b/reference/dom/functions/dom-domdocument-registernodeclass.xml @@ -1,20 +1,112 @@ - + - DOMDocument::registerNodeClass + DOMDocument->registerNodeClass() Register extended class used to create base node type &reftitle.description; - - boolDOMDocument::registerNodeClass - stringbaseclass - stringextendedclass - + + DOMDocument + + boolregisterNodeClass + stringbaseclass + stringextendedclass + + - &warn.undocumented.func; + + This method allows you to register your own extended DOM class to be used + afterward by the PHP DOM extension. + + + This method is not part of the DOM standard. + + + + &reftitle.parameters; + + + + baseclass + + + The DOM class that you want to extend. You can find a list of these + classes in the chapter introduction. + + + Of course, you won't be able to register a class extending DOMDocument + but you can always start your document by instanciating your own + extending class. + + + + + extendedclass + + + Your extended class name. If &null; is provided, any previously + registered class extending baseclass will + be removed. + + + + + + + + + &reftitle.returnvalues; + + &return.success; + + + + + &reftitle.examples; + + + Adding a new method to DOMElement to ease our code + +appendChild(new myElement($name)); + } +} + +class myDocument extends DOMDocument { + function setRoot($name) { + return $this->appendChild(new myElement($name)); + } +} + +$doc = new myDocument(); +$doc->registerNodeClass('DOMElement', 'myElement'); + +// From now on, adding an element to another costs only one method call ! +$root = $doc->setRoot('root'); +$child = $root->appendElement('child'); +$child->setAttribute('foo', 'bar'); + +echo $doc->saveXML(); + +?> +]]> + + &example.outputs; + + + +]]> + + + diff --git a/reference/dom/functions/dom-domdocumentfragment-appendxml.xml b/reference/dom/functions/dom-domdocumentfragment-appendxml.xml index b16d4534b2..f4e7eacbf9 100644 --- a/reference/dom/functions/dom-domdocumentfragment-appendxml.xml +++ b/reference/dom/functions/dom-domdocumentfragment-appendxml.xml @@ -1,10 +1,10 @@ - + - + DOMDocumentFragment->appendXML() - Append XML data + Append raw XML data &reftitle.description; @@ -15,9 +15,18 @@ stringdata - - &warn.undocumented.func; - + + Appends raw XML data to a DOMDocumentFragment. + + + This method is not part of the DOM standard. It was created as a simplier + approach for appending an XML DocumentFragment in a DOMDocument. + + + If you want to stick to the standards, you will have to create a temporary + DOMDocument with a dummy root and then loop through the child nodes of the + root of your XML data to append them. + &reftitle.parameters; @@ -41,85 +50,33 @@ - - - - - - - - - - - diff --git a/reference/dom/reference.xml b/reference/dom/reference.xml index 455280ffce..9b19e550be 100644 --- a/reference/dom/reference.xml +++ b/reference/dom/reference.xml @@ -1,5 +1,5 @@ - + @@ -262,6 +262,9 @@ - Performs relaxNG validation on the document + + - Register extended class used to create base node type (not DOM standard) + - Dumps the internal XML tree back into a file @@ -447,6 +450,21 @@ +
+ <classname>DOMDocumentFragment</classname> + + Extends DOMNode. + +
+ &reftitle.methods; + + + - Append raw XML data (not DOM standard) + + +
+
+
<classname>DOMDocumentType</classname> @@ -1277,7 +1295,7 @@ - chapter.xml + book.xml