1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
13:
14: 15: 16: 17: 18: 19: 20: 21: 22:
23: class Jyxo_XmlReader extends XMLReader
24: {
25: 26: 27: 28: 29:
30: private $textTypes = array(
31: self::TEXT => true,
32: self::WHITESPACE => true,
33: self::SIGNIFICANT_WHITESPACE => true
34: );
35:
36: 37: 38: 39: 40:
41: private $contentTypes = array(
42: self::CDATA => true,
43: self::TEXT => true,
44: self::WHITESPACE => true,
45: self::SIGNIFICANT_WHITESPACE => true
46: );
47:
48: 49: 50: 51: 52:
53: public function getTextValue()
54: {
55: $depth = 1;
56: $text = '';
57:
58: while ((0 !== $depth) && ($this->read())) {
59: if (isset($this->textTypes[$this->nodeType])) {
60: $text .= $this->value;
61: } elseif (self::ELEMENT === $this->nodeType) {
62: if (!$this->isEmptyElement) {
63: $depth++;
64: }
65: } elseif (self::END_ELEMENT === $this->nodeType) {
66: $depth--;
67: }
68: }
69: return $text;
70: }
71:
72: 73: 74: 75: 76:
77: public function getContent()
78: {
79: $depth = 1;
80: $text = '';
81:
82: while ((0 !== $depth) && ($this->read())) {
83: if (isset($this->contentTypes[$this->nodeType])) {
84: $text .= $this->value;
85: } elseif (self::ELEMENT === $this->nodeType) {
86: if ($this->isEmptyElement) {
87: $text .= '<' . $this->name . '/>';
88: } else {
89: $depth++;
90: $text .= '<' . $this->name;
91:
92: while ($this->moveToNextAttribute()) {
93: $text .= ' ' . $this->name . '="' . $this->value . '"';
94: }
95:
96: $text .= '>';
97: }
98: } elseif (self::END_ELEMENT === $this->nodeType) {
99: $depth--;
100: if ($depth > 0) {
101: $text .= '</' . $this->name . '>';
102: }
103: }
104: }
105:
106: return $text;
107: }
108: }
109: