Overview

Namespaces

  • Jyxo
    • Beholder
      • TestCase
    • Gettext
      • Parser
    • Input
      • Chain
      • Filter
      • Validator
    • Mail
      • Email
        • Attachment
      • Parser
      • Sender
    • Rpc
      • Json
      • Xml
    • Shell
    • Spl
    • Svn
    • Time
    • Webdav
  • PHP

Classes

  • Charset
  • Color
  • Css
  • ErrorHandler
  • ErrorMail
  • FirePhp
  • Html
  • HtmlTag
  • SpamFilter
  • String
  • Timer
  • XmlReader

Exceptions

  • Exception
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
  1: <?php
  2: 
  3: /**
  4:  * Jyxo PHP Library
  5:  *
  6:  * LICENSE
  7:  *
  8:  * This source file is subject to the new BSD license that is bundled
  9:  * with this package in the file license.txt.
 10:  * It is also available through the world-wide-web at this URL:
 11:  * https://github.com/jyxo/php/blob/master/license.txt
 12:  */
 13: 
 14: namespace Jyxo;
 15: 
 16: /**
 17:  * XMLReader child class (available since PHP 5.1).
 18:  *
 19:  * @category Jyxo
 20:  * @package Jyxo\XmlReader
 21:  * @copyright Copyright (c) 2005-2011 Jyxo, s.r.o.
 22:  * @license https://github.com/jyxo/php/blob/master/license.txt
 23:  * @author Jaroslav HanslĂ­k
 24:  */
 25: class XmlReader extends \XMLReader
 26: {
 27:     /**
 28:      * Text types list.
 29:      *
 30:      * @var array
 31:      */
 32:     private $textTypes = array(
 33:         self::TEXT => true,
 34:         self::WHITESPACE => true,
 35:         self::SIGNIFICANT_WHITESPACE => true
 36:     );
 37: 
 38:     /**
 39:      * Content types list.
 40:      *
 41:      * @var array
 42:      */
 43:     private $contentTypes = array(
 44:         self::CDATA => true,
 45:         self::TEXT => true,
 46:         self::WHITESPACE => true,
 47:         self::SIGNIFICANT_WHITESPACE => true
 48:     );
 49: 
 50:     /**
 51:      * Returns element's text contents.
 52:      *
 53:      * @return string
 54:      */
 55:     public function getTextValue()
 56:     {
 57:         $depth = 1;
 58:         $text = '';
 59: 
 60:         while ((0 !== $depth) && ($this->read())) {
 61:             if (isset($this->textTypes[$this->nodeType])) {
 62:                 $text .= $this->value;
 63:             } elseif (self::ELEMENT === $this->nodeType) {
 64:                 if (!$this->isEmptyElement) {
 65:                     $depth++;
 66:                 }
 67:             } elseif (self::END_ELEMENT === $this->nodeType) {
 68:                 $depth--;
 69:             }
 70:         }
 71:         return $text;
 72:     }
 73: 
 74:     /**
 75:      * Returns element's contents including tags.
 76:      *
 77:      * @return string
 78:      */
 79:     public function getContent()
 80:     {
 81:         $depth = 1;
 82:         $text = '';
 83: 
 84:         while ((0 !== $depth) && ($this->read())) {
 85:             if (isset($this->contentTypes[$this->nodeType])) {
 86:                 $text .= $this->value;
 87:             } elseif (self::ELEMENT === $this->nodeType) {
 88:                 if ($this->isEmptyElement) {
 89:                     $text .= '<' . $this->name . '/>';
 90:                 } else {
 91:                     $depth++;
 92:                     $text .= '<' . $this->name;
 93: 
 94:                     while ($this->moveToNextAttribute()) {
 95:                         $text .= ' ' . $this->name . '="' . $this->value . '"';
 96:                     }
 97: 
 98:                     $text .= '>';
 99:                 }
100:             } elseif (self::END_ELEMENT === $this->nodeType) {
101:                 $depth--;
102:                 if ($depth > 0) {
103:                     $text .= '</' . $this->name . '>';
104:                 }
105:             }
106:         }
107: 
108:         return $text;
109:     }
110: }
111: 
Jyxo PHP Library API documentation generated by ApiGen 2.3.0