Adds the specified node as the documentElement. |
Signature: appendChild(&$child) |
Parameters:
DOMIT_Node child - The node that is to be appended as documentElement. Only a single node can serve as documentElement, so an existing documentElement node will be overwritten.
|
Returns:
DOMIT_Node - The appended documentElement node.
|
Example:
The documentElement of a tree is assigned using appendChild: $mydoc->appendChild($elementNode); |
Creates a new instance of a DOMIT_Element. |
Signature: createElement($name) |
Parameters:
String name - The tagName of the DOMIT_Element to be created.
|
Returns:
DOMIT_Element - The newly created DOMIT_Element.
|
Example:
A new DOMIT_Element can be created in the following manner: $myBook = $xmldoc->createElement("book"); |
Creates a new instance of a DOMIT_TextNode. |
Signature: createTextNode($text) |
Parameters:
String text - The text of the DOMIT_TextNode to be created.
|
Returns:
DOMIT_TextNode - The newly created DOMIT_TextNode.
|
Example:
A new DOMIT_TextNode can be created in the following manner: $myBookCritique = $xmldoc->createTextNode("A really good read."); |
Creates a new instance of a DOMIT_CDATASection. |
Signature: createCDATASection($text) |
Parameters:
String text - The text of the DOMIT_CDATASection to be created.
|
Returns:
DOMIT_CDATASection - The newly created DOMIT_CDATASection.
|
Example:
A new DOMIT_CDataSection can be created in the following manner: $curseWord = $xmldoc->createCDATASection("&*^%$#@"); |
Generates an DOMIT_NodeList of DOMIT_Elements with the specified $tagName that are present in the document. |
Signature: &getElementsByTagName($tagName) |
Parameters:
String tagName - The tag name of the DOMIT_Elements to be searched for, or "*" if all elements are to be returned.
|
Returns:
DOMIT_NodeList - The DOMIT_NodeList of found DOMIT_Elements.
|
Example:
Here, all elements named "poem" that fall under the $poems node are returned as a DOMIT_NodeList: $poems =& $library->getElementsByTagName("poem"); |
Parses the xml string provided into a hierarchy of DOMIT_Nodes under the current DOMIT_Document. Either the Expat extension or the included SAXY_Parser class can be specified to perform the parsing. |
Signature: parseXML($xmlText, $useSAXY = true) |
Parameters:
String xmlText - The xml text to be parsed.
boolean useSAXY - false (or omitted) if the Expat parser is to be used, true if SAXY is used. Note that since SAXY is not a C extension as is Expat, there is no question as to its availability. It is also slightly faster than Expat, although possibly not as robust.
|
Example:
The xml string will be parsed using the SAXY parser: $xmldoc->parseXML("<book><title>Using DOMIT!</title><author>John Heinstein</author></book>", true); |
Parses the xml string located at the specified url or local file. Either the Expat extension or the included SAXY_Parser class can be specified to perform the parsing. |
Signature: loadXML($fileName, $useSAXY = true) |
Parameters:
String fileName - The file name (url or local file) containing the xml to be parsed.
boolean useSAXY - false (or omitted) if the Expat parser is to be used, true if SAXY is used. Note that since SAXY is not a C extension as is Expat, there is no question as to its availability. It is also slightly faster than Expat, although possibly not as robust.
|
Returns:
boolean - True if the xml parsed properly.
|
Example:
The xml string in file myFile.xml will be parsed using the SAXY parser: $xmldoc->loadXML("http://www.someurl.com/myFile.xml", true); |
Gets the text located at the specified url or local file. |
Signature: getTextFromFile($filename) |
Parameters:
String fileName - The file name (url or local file) containing the text to be retrieved.
|
Returns:
String - The text contained in the specified file.
|
Example:
The string in file myFile.txt will be retrieved: $myText = $xmldoc->getTextFromFile("http://www.someurl.com/myFile.txt"); |
Saves the current DOM document as XML text at the specified location. |
Signature: saveXML($fileName) |
Parameters:
String fileName - The file name (url or local file) to which the XML is to be saved.
|
Returns:
boolean - True if the file is saved properly.
|
Example:
The current document will be saved as myFile.xml: $success = $xmldoc->saveXML("http://www.someurl.com/myFile.xml"); |
Saves the specified text located to the specified url or local file. |
Signature: saveTextToFile($fileName, $text) |
Parameters:
String fileName - The file name (url or local file) where the specified text is to be written.
String text - The text to be written to the specified file name.
|
Returns:
boolean - True if the save is successful.
|
Example:
The specified string will be saved as myFile.txt: $success = $xmldoc->saveTextToFile("../myFile.txt", "This is a test"); |
Returns the name of the parser used to create the document, either "SAXY" or "EXPAT". |
Signature: parsedBy() |
Returns:
String - The name of the parser used to create the document, either "SAXY" or "EXPAT". An empty string is returned if the document is empty.
|
Example:
The name of the parser is returned: $myParser = $xmldoc->parsedBy(); |
Allows you to search the document tree for nodes of a specific type, returning the found nodes in a DOMIT_NodeList. |
Signature: &getNodesByNodeType($type, &$contextNode) |
Parameters:
int type - A DOMIT! constant referring to the node type, one of: DOMIT_DOCUMENT_NODE (9), DOMIT_ELEMENT_NODE (1), DOMIT_TEXT_NODE (3), DOMIT_CDATA_SECTION_NODE (4).
DOMIT_Node contextNode - An element or document node from which the search should begin.
|
Returns:
DOMIT_NodeList - A DOMIT_NodeList containing the found nodes.
|
Example:
All elements in the document will be returned. $allElements =& $xmldoc->getNodesByNodeType(DOMIT_ELEMENT_NODE, $xmldoc); |
Allows you to search the document tree for nodes of a specific value, returning the found nodes in a DOMIT_NodeList. |
Signature: &getNodesByNodeValue($value, &$contextNode) |
Parameters:
String value - The text to search for in any text/cdata nodes that are encountered.
DOMIT_Node contextNode - An element or document node from which the search should begin.
|
Returns:
array - A DOMIT_NodeList containing the found nodes.
|
Example:
All text nodes in the document containing the string "Richard Thompson" will be returned. $textNodes =& $cdCollectionDoc->getNodesByNodeValue("Richard Thompson", $cdCollectionDoc); |
Returns the text contained in all DOMIT_TextNodes and DOMIT_CDataSections that are children of the specified starting node |
Signature: getText() |
Example:
All text and cdata nodes in the document will be concatenated and returned. $allDocmentText = $xmldoc->getText(); |
Generates an unformatted (single line, no whitespace) string representation of the document and all children. |
Signature: toString() |
Returns:
String - An unformatted (single line, no whitespace) string representation of the document and all children.
|
Example:
An unformatted string representation of the xml document will be printed here: echo (htmlentities($myDoc->toString()); |