Fixing file upload params ($_FILES) normalization. Closes #75
[akelos.git] / vendor / domit / xml_saxy_parser.php
bloba4f029bd4d4879ddc9d164c5aad13982c3027c34
1 <?php
2 /**
3 * SAXY is a non-validating, but lightweight and fast SAX parser for PHP, modelled on the Expat parser
4 * @package saxy-xmlparser
5 * @subpackage saxy-xmlparser-main
6 * @version 0.87
7 * @copyright (C) 2004 John Heinstein. All rights reserved
8 * @license http://www.gnu.org/copyleft/lesser.html LGPL License
9 * @author John Heinstein <johnkarl@nbnet.nb.ca>
10 * @link http://www.engageinteractive.com/saxy/ SAXY Home Page
11 * SAXY is Free Software
12 **/
14 if (!defined('SAXY_INCLUDE_PATH')) {
15 define('SAXY_INCLUDE_PATH', (dirname(__FILE__) . "/"));
18 /** current version of SAXY */
19 define ('SAXY_VERSION', '0.87');
21 /** default XML namespace */
22 define ('SAXY_XML_NAMESPACE', 'http://www.w3.org/xml/1998/namespace');
24 /** saxy parse state, before prolog is encountered */
25 define('SAXY_STATE_PROLOG_NONE', 0);
26 /** saxy parse state, in processing instruction */
27 define('SAXY_STATE_PROLOG_PROCESSINGINSTRUCTION', 1);
28 /** saxy parse state, an exclamation mark has been encountered */
29 define('SAXY_STATE_PROLOG_EXCLAMATION', 2);
30 /** saxy parse state, in DTD */
31 define('SAXY_STATE_PROLOG_DTD', 3);
32 /** saxy parse state, an inline DTD */
33 define('SAXY_STATE_PROLOG_INLINEDTD', 4);
34 /** saxy parse state, a comment */
35 define('SAXY_STATE_PROLOG_COMMENT', 5);
36 /** saxy parse state, processing main document */
37 define('SAXY_STATE_PARSING', 6);
38 /** saxy parse state, processing comment in main document */
39 define('SAXY_STATE_PARSING_COMMENT', 7);
41 //SAXY error codes; same as EXPAT error codes
42 /** no error */
43 define('SAXY_XML_ERROR_NONE', 0);
44 /** out of memory error */
45 define('SAXY_XML_ERROR_NO_MEMORY', 1);
46 /** syntax error */
47 define('SAXY_XML_ERROR_SYNTAX', 2);
48 /** no elements in document */
49 define('SAXY_XML_ERROR_NO_ELEMENTS', 3);
50 /** invalid token encountered error */
51 define('SAXY_XML_ERROR_INVALID_TOKEN', 4);
52 /** unclosed token error */
53 define('SAXY_XML_ERROR_UNCLOSED_TOKEN', 5);
54 /** partial character error */
55 define('SAXY_XML_ERROR_PARTIAL_CHAR', 6);
56 /** mismatched tag error */
57 define('SAXY_XML_ERROR_TAG_MISMATCH', 7);
58 /** duplicate attribute error */
59 define('SAXY_XML_ERROR_DUPLICATE_ATTRIBUTE', 8);
60 /** junk after document element error */
61 define('SAXY_XML_ERROR_JUNK_AFTER_DOC_ELEMENT', 9);
62 /** parameter enitity reference error */
63 define('SAXY_XML_ERROR_PARAM_ENTITY_REF', 10);
64 /** undefined entity error */
65 define('SAXY_XML_ERROR_UNDEFINED_ENTITY', 11);
66 /** recursive entity error */
67 define('SAXY_XML_ERROR_RECURSIVE_ENTITY_REF', 12);
68 /** asynchronous entity error */
69 define('SAXY_XML_ERROR_ASYNC_ENTITY', 13);
70 /** bad character reference error */
71 define('SAXY_XML_ERROR_BAD_CHAR_REF', 14);
72 /** binary entity reference error */
73 define('SAXY_XML_ERROR_BINARY_ENTITY_REF', 15);
74 /** attribute external entity error */
75 define('SAXY_XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF', 16);
76 /** misplaced processing instruction error */
77 define('SAXY_XML_ERROR_MISPLACED_XML_PI', 17);
78 /** unknown encoding error */
79 define('SAXY_XML_ERROR_UNKNOWN_ENCODING', 18);
80 /** incorrect encoding error */
81 define('SAXY_XML_ERROR_INCORRECT_ENCODING', 19);
82 /** unclosed CDATA Section error */
83 define('SAXY_XML_ERROR_UNCLOSED_CDATA_SECTION', 20);
84 /** external entity handling error */
85 define('SAXY_XML_ERROR_EXTERNAL_ENTITY_HANDLING', 21);
87 require_once(SAXY_INCLUDE_PATH . 'xml_saxy_shared.php');
89 /**
90 * The SAX Parser class
92 * @package saxy-xmlparser
93 * @subpackage saxy-xmlparser-main
94 * @author John Heinstein <johnkarl@nbnet.nb.ca>
96 class SAXY_Parser extends SAXY_Parser_Base {
97 /** @var int The current error number */
98 var $errorCode = SAXY_XML_ERROR_NONE;
99 /** @var Object A reference to the DocType event handler */
100 var $DTDHandler = null;
101 /** @var Object A reference to the Comment event handler */
102 var $commentHandler = null;
103 /** @var Object A reference to the Processing Instruction event handler */
104 var $processingInstructionHandler = null;
105 /** @var Object A reference to the Start Namespace Declaration event handler */
106 var $startNamespaceDeclarationHandler = null;
107 /** @var Object A reference to the End Namespace Declaration event handler */
108 var $endNamespaceDeclarationHandler = null;
109 /** @var boolean True if SAXY takes namespaces into consideration when parsing element tags */
110 var $isNamespaceAware = false;
111 /** @var array An indexed array containing associative arrays of namespace prefixes mapped to their namespace URIs */
112 var $namespaceMap = array();
113 /** @var array A stack used to determine when an end namespace event should be fired */
114 var $namespaceStack = array();
115 /** @var array A track used to track the uri of the current default namespace */
116 var $defaultNamespaceStack = array();
117 /** @var array A stack containing tag names of unclosed elements */
118 var $elementNameStack = array();
122 * Constructor for SAX parser
124 function SAXY_Parser() {
125 $this->SAXY_Parser_Base();
126 $this->state = SAXY_STATE_PROLOG_NONE;
127 } //SAXY_Parser
130 * Sets a reference to the handler for the DocType event
131 * @param mixed A reference to the DocType handler
133 function xml_set_doctype_handler($handler) {
134 $this->DTDHandler =& $handler;
135 } //xml_set_doctype_handler
138 * Sets a reference to the handler for the Comment event
139 * @param mixed A reference to the Comment handler
141 function xml_set_comment_handler($handler) {
142 $this->commentHandler =& $handler;
143 } //xml_set_comment_handler
146 * Sets a reference to the handler for the Processing Instruction event
147 * @param mixed A reference to the Processing Instruction handler
149 function xml_set_processing_instruction_handler($handler) {
150 $this->processingInstructionHandler =& $handler;
151 } //xml_set_processing_instruction_handler
154 * Sets a reference to the handler for the Start Namespace Declaration event
155 * @param mixed A reference to the Start Namespace Declaration handler
157 function xml_set_start_namespace_decl_handler($handler) {
158 $this->startNamespaceDeclarationHandler =& $handler;
159 } //xml_set_start_namespace_decl_handler
162 * Sets a reference to the handler for the End Namespace Declaration event
163 * @param mixed A reference to the Start Namespace Declaration handler
165 function xml_set_end_namespace_decl_handler($handler) {
166 $this->endNamespaceDeclarationHandler =& $handler;
167 } //xml_set_end_namespace_decl_handler
170 * Specifies whether SAXY is namespace sensitive
171 * @param boolean True if SAXY is namespace aware
173 function setNamespaceAwareness($isNamespaceAware) {
174 $this->isNamespaceAware =& $isNamespaceAware;
175 } //setNamespaceAwareness
178 * Returns the current version of SAXY
179 * @return Object The current version of SAXY
181 function getVersion() {
182 return SAXY_VERSION;
183 } //getVersion
186 * Processes the xml prolog, doctype, and any other nodes that exist outside of the main xml document
187 * @param string The xml text to be processed
188 * @return string The preprocessed xml text
190 function preprocessXML($xmlText) {
191 //strip prolog
192 $xmlText = trim($xmlText);
193 $startChar = -1;
194 $total = strlen($xmlText);
196 for ($i = 0; $i < $total; $i++) {
197 $currentChar = $xmlText{$i};
199 switch ($this->state) {
200 case SAXY_STATE_PROLOG_NONE:
201 if ($currentChar == '<') {
202 $nextChar = $xmlText{($i + 1)};
204 if ($nextChar == '?') {
205 $this->state = SAXY_STATE_PROLOG_PROCESSINGINSTRUCTION;
206 $this->charContainer = '';
208 else if ($nextChar == '!') {
209 $this->state = SAXY_STATE_PROLOG_EXCLAMATION;
210 $this->charContainer .= $currentChar;
211 break;
213 else {
214 $this->charContainer = '';
215 $startChar = $i;
216 $this->state = SAXY_STATE_PARSING;
217 return (substr($xmlText, $startChar));
221 break;
223 case SAXY_STATE_PROLOG_EXCLAMATION:
224 if ($currentChar == 'D') {
225 $this->state = SAXY_STATE_PROLOG_DTD;
226 $this->charContainer .= $currentChar;
228 else if ($currentChar == '-') {
229 $this->state = SAXY_STATE_PROLOG_COMMENT;
230 $this->charContainer = '';
232 else {
233 //will trap ! and add it
234 $this->charContainer .= $currentChar;
237 break;
239 case SAXY_STATE_PROLOG_PROCESSINGINSTRUCTION:
240 if ($currentChar == '>') {
241 $this->state = SAXY_STATE_PROLOG_NONE;
242 $this->parseProcessingInstruction($this->charContainer);
243 $this->charContainer = '';
245 else {
246 $this->charContainer .= $currentChar;
249 break;
251 case SAXY_STATE_PROLOG_COMMENT:
252 if ($currentChar == '>') {
253 $this->state = SAXY_STATE_PROLOG_NONE;
254 $this->parseComment($this->charContainer);
255 $this->charContainer = '';
257 else if ($currentChar == '-') {
258 if ((($xmlText{($i + 1)} == '-') && ($xmlText{($i + 2)} == '>')) ||
259 ($xmlText{($i + 1)} == '>') ||
260 (($xmlText{($i - 1)} == '-') && ($xmlText{($i - 2)}== '!')) ){
261 //do nothing
263 else {
264 $this->charContainer .= $currentChar;
267 else {
268 $this->charContainer .= $currentChar;
271 break;
273 case SAXY_STATE_PROLOG_DTD:
274 if ($currentChar == '[') {
275 $this->charContainer .= $currentChar;
276 $this->state = SAXY_STATE_PROLOG_INLINEDTD;
278 else if ($currentChar == '>') {
279 $this->state = SAXY_STATE_PROLOG_NONE;
281 if ($this->DTDHandler != null) {
282 $this->fireDTDEvent($this->charContainer . $currentChar);
285 $this->charContainer = '';
287 else {
288 $this->charContainer .= $currentChar;
291 break;
293 case SAXY_STATE_PROLOG_INLINEDTD:
294 $previousChar = $xmlText{($i - 1)};
296 if (($currentChar == '>') && ($previousChar == ']')){
297 $this->state = SAXY_STATE_PROLOG_NONE;
299 if ($this->DTDHandler != null) {
300 $this->fireDTDEvent($this->charContainer . $currentChar);
303 $this->charContainer = '';
305 else {
306 $this->charContainer .= $currentChar;
309 break;
313 } //preprocessXML
316 * The controlling method for the parsing process
317 * @param string The xml text to be processed
318 * @return boolean True if parsing is successful
320 function parse ($xmlText) {
321 $xmlText = $this->preprocessXML($xmlText);
322 $total = strlen($xmlText);
324 for ($i = 0; $i < $total; $i++) {
325 $currentChar = $xmlText{$i};
327 switch ($this->state) {
328 case SAXY_STATE_PARSING:
329 switch ($currentChar) {
330 case '<':
331 if (substr($this->charContainer, 0, SAXY_CDATA_LEN) == SAXY_SEARCH_CDATA) {
332 $this->charContainer .= $currentChar;
334 else {
335 $this->parseBetweenTags($this->charContainer);
336 $this->charContainer = '';
338 break;
340 case '-':
341 if (($xmlText{($i - 1)} == '-') && ($xmlText{($i - 2)} == '!')) {
342 $this->state = SAXY_STATE_PARSING_COMMENT;
343 $this->charContainer = '';
345 else {
346 $this->charContainer .= $currentChar;
348 break;
350 case '>':
351 if ((substr($this->charContainer, 0, SAXY_CDATA_LEN) == SAXY_SEARCH_CDATA) &&
352 !(($this->getCharFromEnd($this->charContainer, 0) == ']') &&
353 ($this->getCharFromEnd($this->charContainer, 1) == ']'))) {
354 $this->charContainer .= $currentChar;
356 else {
357 $this->parseTag($this->charContainer);
358 $this->charContainer = '';
360 break;
362 default:
363 $this->charContainer .= $currentChar;
366 break;
368 case SAXY_STATE_PARSING_COMMENT:
369 switch ($currentChar) {
370 case '>':
371 if (($xmlText{($i - 1)} == '-') && ($xmlText{($i - 2)} == '-')) {
372 $this->fireCommentEvent(substr($this->charContainer, 0,
373 (strlen($this->charContainer) - 2)));
374 $this->charContainer = '';
375 $this->state = SAXY_STATE_PARSING;
377 else {
378 $this->charContainer .= $currentChar;
380 break;
382 default:
383 $this->charContainer .= $currentChar;
386 break;
390 return ($this->errorCode == 0);
391 } //parse
394 * Parses an element tag
395 * @param string The interior text of the element tag
397 function parseTag($tagText) {
398 $tagText = trim($tagText);
399 $firstChar = $tagText{0};
400 $myAttributes = array();
402 switch ($firstChar) {
403 case '/':
404 $tagName = substr($tagText, 1);
405 $this->_fireEndElementEvent($tagName);
406 break;
408 case '!':
409 $upperCaseTagText = strtoupper($tagText);
411 if (strpos($upperCaseTagText, SAXY_SEARCH_CDATA) !== false) { //CDATA Section
412 $total = strlen($tagText);
413 $openBraceCount = 0;
414 $textNodeText = '';
416 for ($i = 0; $i < $total; $i++) {
417 $currentChar = $tagText{$i};
419 if (($currentChar == ']') && ($tagText{($i + 1)} == ']')) {
420 break;
422 else if ($openBraceCount > 1) {
423 $textNodeText .= $currentChar;
425 else if ($currentChar == '[') { //this won't be reached after the first open brace is found
426 $openBraceCount ++;
430 if ($this->cDataSectionHandler == null) {
431 $this->fireCharacterDataEvent($textNodeText);
433 else {
434 $this->fireCDataSectionEvent($textNodeText);
437 else if (strpos($upperCaseTagText, SAXY_SEARCH_NOTATION) !== false) { //NOTATION node, discard
438 return;
441 else if (substr($tagText, 0, 2) == '!-') { //comment node
442 if ($this->commentHandler != null) {
443 $this->fireCommentEvent(substr($tagText, 3, (strlen($tagText) - 5)));
447 break;
449 case '?':
450 //Processing Instruction node
451 $this->parseProcessingInstruction($tagText);
452 break;
454 default:
455 if ((strpos($tagText, '"') !== false) || (strpos($tagText, "'") !== false)) {
456 $total = strlen($tagText);
457 $tagName = '';
459 for ($i = 0; $i < $total; $i++) {
460 $currentChar = $tagText{$i};
462 if (($currentChar == ' ') || ($currentChar == "\t") ||
463 ($currentChar == "\n") || ($currentChar == "\r") ||
464 ($currentChar == "\x0B")) {
465 $myAttributes = $this->parseAttributes(substr($tagText, $i));
466 break;
468 else {
469 $tagName .= $currentChar;
473 if (strrpos($tagText, '/') == (strlen($tagText) - 1)) { //check $tagText, but send $tagName
474 $this->_fireStartElementEvent($tagName, $myAttributes);
475 $this->_fireEndElementEvent($tagName);
477 else {
478 $this->_fireStartElementEvent($tagName, $myAttributes);
481 else {
482 if (strpos($tagText, '/') !== false) {
483 $tagText = trim(substr($tagText, 0, (strrchr($tagText, '/') - 1)));
484 $this->_fireStartElementEvent($tagText, $myAttributes);
485 $this->_fireEndElementEvent($tagText);
487 else {
488 $this->_fireStartElementEvent($tagText, $myAttributes);
492 } //parseTag
495 * Fires a start element event and pushes the element name onto the elementName stack
496 * @param string The start element tag name
497 * @param Array The start element attributes
499 function _fireStartElementEvent($tagName, &$myAttributes) {
500 $this->elementNameStack[] = $tagName;
502 if ($this->isNamespaceAware) {
503 $this->detectStartNamespaceDeclaration($myAttributes);
504 $tagName = $this->expandNamespacePrefix($tagName);
506 $this->expandAttributePrefixes($myAttributes);
509 $this->fireStartElementEvent($tagName, $myAttributes);
510 } //_fireStartElementEvent
513 * Expands attribute prefixes to full namespace uri
514 * @param Array The start element attributes
516 function expandAttributePrefixes(&$myAttributes) {
517 $arTransform = array();
519 foreach ($myAttributes as $key => $value) {
520 if (strpos($key, 'xmlns') === false) {
521 if (strpos($key, ':') !== false) {
522 $expandedTag = $this->expandNamespacePrefix($key);
523 $arTransform[$key] = $expandedTag;
528 foreach ($arTransform as $key => $value) {
529 $myAttributes[$value] = $myAttributes[$key];
530 unset($myAttributes[$key]);
532 } //expandAttributePrefixes
535 * Expands the namespace prefix (if one exists) to the full namespace uri
536 * @param string The tagName with the namespace prefix
537 * @return string The tagName, with the prefix expanded to the namespace uri
539 function expandNamespacePrefix($tagName) {
540 $stackLen = count($this->defaultNamespaceStack);
541 $defaultNamespace = $this->defaultNamespaceStack[($stackLen - 1)];
543 $colonIndex = strpos($tagName, ':');
545 if ($colonIndex !== false) {
546 $prefix = substr($tagName, 0, $colonIndex);
548 if ($prefix != 'xml') {
549 $tagName = $this->getNamespaceURI($prefix) . substr($tagName, $colonIndex);
551 else {
552 $tagName = SAXY_XML_NAMESPACE . substr($tagName, $colonIndex);
555 else if ($defaultNamespace != '') {
556 $tagName = $defaultNamespace . ':' . $tagName;
559 return $tagName;
560 } //expandNamespacePrefix
563 * Searches the namespaceMap for the specified prefix, and returns the full namespace URI
564 * @param string The namespace prefix
565 * @return string The namespace uri
567 function getNamespaceURI($prefix) {
568 $total = count($this->namespaceMap);
569 $uri = $prefix; //in case uri can't be found, just send back prefix
570 //should really generate an error, but worry about this later
571 //reset($this->namespaceMap);
573 for ($i = ($total - 1); $i >= 0; $i--) {
574 $currMap =& $this->namespaceMap[$i];
576 if (isset($currMap[$prefix])) {
577 $uri = $currMap[$prefix];
578 break;
582 return $uri;
583 } //getNamespaceURI
586 * Searches the attributes array for an xmlns declaration and fires an event if found
587 * @param Array The start element attributes
589 function detectStartNamespaceDeclaration($myAttributes) {
590 $namespaceExists = false;
591 $namespaceMapUpper = 0;
592 $userDefinedDefaultNamespace = false;
593 $total = count($myAttributes);
595 foreach ($myAttributes as $key => $value) {
596 if (strpos($key, 'xmlns') !== false) {
597 //add an array to store all namespaces for the current element
598 if (!$namespaceExists) {
599 $this->namespaceMap[] = array();
600 $namespaceMapUpper = count($this->namespaceMap) - 1;
603 //check for default namespace override, i.e. xmlns='...'
604 if (strpos($key, ':') !== false) {
605 $prefix = $namespaceMapKey = substr($key, 6);
606 $this->namespaceMap[$namespaceMapUpper][$namespaceMapKey] = $value;
608 else {
609 $prefix = '';
610 $userDefinedDefaultNamespace = true;
612 //if default namespace '', store in map using key ':'
613 $this->namespaceMap[$namespaceMapUpper][':'] = $value;
614 $this->defaultNamespaceStack[] = $value;
617 $this->fireStartNamespaceDeclarationEvent($prefix, $value);
618 $namespaceExists = true;
622 //store the default namespace (inherited from the parent elements so grab last one)
623 if (!$userDefinedDefaultNamespace) {
624 $stackLen = count($this->defaultNamespaceStack);
625 if ($stackLen == 0) {
626 $this->defaultNamespaceStack[] = '';
628 else {
629 $this->defaultNamespaceStack[] =
630 $this->defaultNamespaceStack[($stackLen - 1)];
634 $this->namespaceStack[] = $namespaceExists;
635 } //detectStartNamespaceDeclaration
638 * Fires an end element event and pops the element name from the elementName stack
639 * @param string The end element tag name
641 function _fireEndElementEvent($tagName) {
642 $lastTagName = array_pop($this->elementNameStack);
644 //check for mismatched tag error
645 if ($lastTagName != $tagName) {
646 $this->errorCode = SAXY_XML_ERROR_TAG_MISMATCH;
649 if ($this->isNamespaceAware) {
650 $tagName = $this->expandNamespacePrefix($tagName);
651 $this->fireEndElementEvent($tagName);
652 $this->detectEndNamespaceDeclaration();
653 $defaultNamespace = array_pop($this->defaultNamespaceStack);
655 else {
656 $this->fireEndElementEvent($tagName);
658 } //_fireEndElementEvent
661 * Determines whether an end namespace declaration event should be fired
663 function detectEndNamespaceDeclaration() {
664 $isNamespaceEnded = array_pop($this->namespaceStack);
666 if ($isNamespaceEnded) {
667 $map = array_pop($this->namespaceMap);
669 foreach ($map as $key => $value) {
670 if ($key == ':') {
671 $key = '';
673 $this->fireEndNamespaceDeclarationEvent($key);
676 } //detectEndNamespaceDeclaration
679 * Parses a processing instruction
680 * @param string The interior text of the processing instruction
682 function parseProcessingInstruction($data) {
683 $endTarget = 0;
684 $total = strlen($data);
686 for ($x = 2; $x < $total; $x++) {
687 if (trim($data{$x}) == '') {
688 $endTarget = $x;
689 break;
693 $target = substr($data, 1, ($endTarget - 1));
694 $data = substr($data, ($endTarget + 1), ($total - $endTarget - 2));
696 if ($this->processingInstructionHandler != null) {
697 $this->fireProcessingInstructionEvent($target, $data);
699 } //parseProcessingInstruction
702 * Parses a comment
703 * @param string The interior text of the comment
705 function parseComment($data) {
706 if ($this->commentHandler != null) {
707 $this->fireCommentEvent($data);
709 } //parseComment
712 * Fires a doctype event
713 * @param string The doctype data
715 function fireDTDEvent($data) {
716 call_user_func($this->DTDHandler, $this, $data);
717 } //fireDTDEvent
720 * Fires a comment event
721 * @param string The text of the comment
723 function fireCommentEvent($data) {
724 call_user_func($this->commentHandler, $this, $data);
725 } //fireCommentEvent
728 * Fires a processing instruction event
729 * @param string The processing instruction data
731 function fireProcessingInstructionEvent($target, $data) {
732 call_user_func($this->processingInstructionHandler, $this, $target, $data);
733 } //fireProcessingInstructionEvent
736 * Fires a start namespace declaration event
737 * @param string The namespace prefix
738 * @param string The namespace uri
740 function fireStartNamespaceDeclarationEvent($prefix, $uri) {
741 call_user_func($this->startNamespaceDeclarationHandler, $this, $prefix, $uri);
742 } //fireStartNamespaceDeclarationEvent
745 * Fires an end namespace declaration event
746 * @param string The namespace prefix
748 function fireEndNamespaceDeclarationEvent($prefix) {
749 call_user_func($this->endNamespaceDeclarationHandler, $this, $prefix);
750 } //fireEndNamespaceDeclarationEvent
753 * Returns the current error code
754 * @return int The current error code
756 function xml_get_error_code() {
757 return $this->errorCode;
758 } //xml_get_error_code
761 * Returns a textual description of the error code
762 * @param int The error code
763 * @return string The error message
765 function xml_error_string($code) {
766 switch ($code) {
767 case SAXY_XML_ERROR_NONE:
768 return "No error";
769 break;
770 case SAXY_XML_ERROR_NO_MEMORY:
771 return "Out of memory";
772 break;
773 case SAXY_XML_ERROR_SYNTAX:
774 return "Syntax error";
775 break;
776 case SAXY_XML_ERROR_NO_ELEMENTS:
777 return "No elements in document";
778 break;
779 case SAXY_XML_ERROR_INVALID_TOKEN:
780 return "Invalid token";
781 break;
782 case SAXY_XML_ERROR_UNCLOSED_TOKEN:
783 return "Unclosed token";
784 break;
785 case SAXY_XML_ERROR_PARTIAL_CHAR:
786 return "Partial character";
787 break;
788 case SAXY_XML_ERROR_TAG_MISMATCH:
789 return "Tag mismatch";
790 break;
791 case SAXY_XML_ERROR_DUPLICATE_ATTRIBUTE:
792 return "Duplicate attribute";
793 break;
794 case SAXY_XML_ERROR_JUNK_AFTER_DOC_ELEMENT:
795 return "Junk encountered after document element";
796 break;
797 case SAXY_XML_ERROR_PARAM_ENTITY_REF:
798 return "Parameter entity reference error";
799 break;
800 case SAXY_XML_ERROR_UNDEFINED_ENTITY:
801 return "Undefined entity";
802 break;
803 case SAXY_XML_ERROR_RECURSIVE_ENTITY_REF:
804 return "Recursive entity reference";
805 break;
806 case SAXY_XML_ERROR_ASYNC_ENTITY:
807 return "Asynchronous internal entity found in external entity";
808 break;
809 case SAXY_XML_ERROR_BAD_CHAR_REF:
810 return "Bad character reference";
811 break;
812 case SAXY_XML_ERROR_BINARY_ENTITY_REF:
813 return "Binary entity reference";
814 break;
815 case SAXY_XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF:
816 return "Attribute external entity reference";
817 break;
818 case SAXY_XML_ERROR_MISPLACED_XML_PI:
819 return "Misplaced processing instruction";
820 break;
821 case SAXY_XML_ERROR_UNKNOWN_ENCODING:
822 return "Unknown encoding";
823 break;
824 case SAXY_XML_ERROR_INCORRECT_ENCODING:
825 return "Incorrect encoding";
826 break;
827 case SAXY_XML_ERROR_UNCLOSED_CDATA_SECTION:
828 return "Unclosed CDATA Section";
829 break;
830 case SAXY_XML_ERROR_EXTERNAL_ENTITY_HANDLING:
831 return "Problem in external entity handling";
832 break;
833 default:
834 return "No definition for error code " . $code;
835 break;
837 } //xml_error_string
839 } //SAXY_Parser