Class DOMIT_Document
A class representing the DOM Document.

isPublic? yes
isAbstract? no

Inheritance tree:

DOMIT_Node
|
DOMIT_Document

Known subclasses:

None

Source file: xml_domit_parser.php

Includes: xml_domit_utilities.php,xml_domit_getelementsbypath.php,xml_domit_nodemaps.php




Constructor
Initializes DOMIT_Document variables and those of the superclass.

Signature: DOMIT_Document()

isPublic? no




Public Constants



Private Constants



Public Fields
xmlDeclaration
A string representing the xml declaration of the document. Note that this value must be manually assigned; neither the SAXY nor the Expat parsers process xml declarations.

Type: String

doctype
A string representing the document type of the document. Note that this value must be manually assigned; neither the SAXY nor the Expat parsers process document types.

Type: String

documentElement
A reference to the root element of the DOMIT_Document. Null if unassigned.

Type: DOMIT_Element

parser
Contains the name of the parser used to create the DOMIT_Document, either "SAXY" or "EXPAT". If the document is empty, an empty string will be returned.

Type: String




Private Fields



Public Methods
appendChild
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);

createElement
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");

createTextNode
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.");

createCDATASection
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("&*^%$#@");

getElementsByTagName
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");

parseXML
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);

loadXML
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);

getTextFromFile
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");

saveXML
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");

saveTextToFile
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");

parsedBy
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();

getNodesByNodeType
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);

getNodesByNodeValue
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);

getText
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();

toString
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());




Private Methods
createClone
Used by cloneNode() to generate a new instance of a DOMIT_Document containing the same data as the original.

Signature: &createClone()

Returns:

DOMIT_Document - A new DOMIT_Document


Documentation generated by ClassyDoc, using the DOMIT! and SAXY parsers.
Please visit Engage Interactive to download free copies.