3 * @package domit-xmlparser
5 * @copyright (C) 2004 John Heinstein. All rights reserved
6 * @author John Heinstein <johnkarl@nbnet.nb.ca>
7 * @link http://www.engageinteractive.com/domit/ DOMIT! Home Page
8 * DOMIT! is Free Software
11 if (!defined('DOMIT_INCLUDE_PATH')) {
12 /* Path to DOMIT! files */
13 define('DOMIT_INCLUDE_PATH', (dirname(__FILE__
) . "/"));
17 /** DOM Element nodeType */
18 define('DOMIT_ELEMENT_NODE', 1);
19 /** DOM Attr nodeType */
20 define('DOMIT_ATTRIBUTE_NODE', 2);
21 /** DOM Text nodeType */
22 define('DOMIT_TEXT_NODE', 3);
23 /** DOM CDATA Section nodeType */
24 define('DOMIT_CDATA_SECTION_NODE', 4);
25 /** DOM Entity Reference nodeType */
26 define('DOMIT_ENTITY_REFERENCE_NODE', 5);
27 /** DOM Entity nodeType */
28 define('DOMIT_ENTITY_NODE', 6);
29 /** DOM Processing Instruction nodeType */
30 define('DOMIT_PROCESSING_INSTRUCTION_NODE', 7);
31 /** DOM Comment nodeType */
32 define('DOMIT_COMMENT_NODE', 8);
33 /** DOM Document nodeType */
34 define('DOMIT_DOCUMENT_NODE', 9);
35 /** DOM DocType nodeType */
36 define('DOMIT_DOCUMENT_TYPE_NODE', 10);
37 /** DOM Document Fragment nodeType */
38 define('DOMIT_DOCUMENT_FRAGMENT_NODE', 11);
39 /** DOM Notation nodeType */
40 define('DOMIT_NOTATION_NODE', 12);
42 //DOM Level 1 Exceptions
43 /** DOM error: array index out of bounds */
44 define('DOMIT_INDEX_SIZE_ERR', 1);
45 /** DOM error: text doesn't fit into a DOMString */
46 define('DOMIT_DOMSTRING_SIZE_ERR', 2);
47 /** DOM error: node can't be inserted at this location */
48 define('DOMIT_HIERARCHY_REQUEST_ERR', 3);
49 /** DOM error: node not a child of target document */
50 define('DOMIT_WRONG_DOCUMENT_ERR', 4);
51 /** DOM error: invalid character specified */
52 define('DOMIT_INVALID_CHARACTER_ERR', 5);
53 /** DOM error: data can't be added to current node */
54 define('DOMIT_NO_DATA_ALLOWED_ERR', 6);
55 /** DOM error: node is read-only */
56 define('DOMIT_NO_MODIFICATION_ALLOWED_ERR', 7);
57 /** DOM error: node can't be found in specified context */
58 define('DOMIT_NOT_FOUND_ERR', 8);
59 /** DOM error: operation not supported by current implementation */
60 define('DOMIT_NOT_SUPPORTED_ERR', 9);
61 /** DOM error: attribute currently in use elsewhere */
62 define('DOMIT_INUSE_ATTRIBUTE_ERR', 10);
64 //DOM Level 2 Exceptions
65 /** DOM error: attempt made to use an object that is no longer usable */
66 define('DOMIT_INVALID_STATE_ERR', 11);
67 /** DOM error: invalid or illegal string specified */
68 define('DOMIT_SYNTAX_ERR', 12);
69 /** DOM error: can't modify underlying type of node */
70 define('DOMIT_INVALID_MODIFICATION_ERR', 13);
71 /** DOM error: attempt to change node in a way incompatible with namespaces */
72 define('DOMIT_NAMESPACE_ERR', 14);
73 /** DOM error: operation unsupported by underlying object */
74 define('DOMIT_INVALID_ACCESS_ERR', 15);
77 /** DOM error: attempt to instantiate abstract class */
78 define('DOMIT_ABSTRACT_CLASS_INSTANTIATION_ERR', 100);
79 /** DOM error: attempt to call abstract method */
80 define('DOMIT_ABSTRACT_METHOD_INVOCATION_ERR', 101);
81 /** DOM error: can't perform this action on or with Document Fragment */
82 define('DOMIT_DOCUMENT_FRAGMENT_ERR', 102);
85 *@global Object Instance of the UIDGenerator class
87 $GLOBALS['uidFactory'] = new UIDGenerator();
89 require_once(DOMIT_INCLUDE_PATH
. 'xml_domit_nodemaps.php');
92 * Generates unique ids for each node
94 * @package domit-xmlparser
95 * @author John Heinstein <johnkarl@nbnet.nb.ca>
98 /** @var int A seed value for generating uids */
100 /** @var int A tally of the number of uids generated */
104 * UIDGenerator constructor
106 function UIDGenerator() {
107 $this->seed
= 'node' . time();
111 * Generates a unique id
114 function generateUID() {
115 return ($this->seed
. $this->counter++
);
121 * A DOMIT! exception handling class
123 * @package domit-xmlparser
124 * @author John Heinstein <johnkarl@nbnet.nb.ca>
126 class DOMIT_DOMException
{
128 * Raises the specified exception
129 * @param int The error number
130 * @param string A string explanation of the error
132 function raiseException($errorNum, $errorString) {
133 $errorMessage = 'Error: ' . $errorNum . "\n " . $errorString;
135 if ((!isset($GLOBALS['DOMIT_ERROR_FORMATTING_HTML'])) ||
136 ($GLOBALS['DOMIT_ERROR_FORMATTING_HTML'] == true)) {
137 $errorMessage = "<p><pre>" . $errorMessage . "</pre></p>";
142 } //DOMIT_DOMException
145 * A class representing the DOM Implementation node
147 * @package domit-xmlparser
148 * @author John Heinstein <johnkarl@nbnet.nb.ca>
150 class DOMIT_DOMImplementation
{
151 function hasFeature($feature, $version = null) {
152 if (strtoupper($feature) == 'XML') {
153 if (($version == '1.0') ||
($version == '2.0') ||
($version == null)) {
162 * Creates a new DOMIT_Document node and appends a documentElement with the specified info
163 * @param string The namespaceURI of the documentElement
164 * @param string The $qualifiedName of the documentElement
165 * @param Object A document type node
166 * @return Object The new document fragment node
168 function &createDocument($namespaceURI, $qualifiedName, &$docType) {
169 $xmldoc =& new DOMIT_Document();
170 $documentElement =& $xmldoc->createElementNS($namespaceURI, $qualifiedName);
172 $xmldoc->setDocumentElement($documentElement);
174 if ($docType != null) {
175 $xmldoc->doctype
=& $docType;
182 * Creates a new DOMIT_DocumentType node (not yet implemented!)
183 * @param string The $qualifiedName
184 * @param string The $publicID
185 * @param string The $systemID
186 * @return Object The new document type node
188 function &createDocumentType($qualifiedName, $publicID, $systemID) {
189 //not yet implemented
190 DOMIT_DOMException
::raiseException(DOMIT_NOT_SUPPORTED_ERROR
,
191 ('Method createDocumentType is not yet implemented.'));
192 } //createDocumentType
193 } //DOMIT_DOMImplementation