1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
13:
14: namespace Jyxo;
15:
16: 17: 18: 19: 20: 21: 22: 23: 24:
25: class XmlReader extends \XMLReader
26: {
27: 28: 29: 30: 31:
32: private $textTypes = array(
33: self::TEXT => true,
34: self::WHITESPACE => true,
35: self::SIGNIFICANT_WHITESPACE => true
36: );
37:
38: 39: 40: 41: 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: 52: 53: 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: 76: 77: 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: