1 | <?php |
||
51 | class QuiteSimpleXMLElement |
||
52 | { |
||
53 | public $namespaces; |
||
54 | public $el; |
||
55 | |||
56 | # |
||
57 | # See https://github.com/draffter/FollowFunctionPHP/blob/master/_php/SimpleXML.php |
||
58 | # for list of functions with arguments |
||
59 | # |
||
60 | public function __construct($elem, $inherit_from=null) |
||
88 | |||
89 | public function registerXPathNamespace($prefix, $uri) |
||
94 | |||
95 | public function registerXPathNamespaces($namespaces) |
||
102 | |||
103 | /* |
||
104 | * Convenience method for getting the text of the first |
||
105 | * node matching an xpath. The text is trimmed by default, |
||
106 | * but setting the second argument to false will return |
||
107 | * the untrimmed text. |
||
108 | */ |
||
109 | public function text($path = '.', $trim=true) |
||
110 | { |
||
111 | $text = strval($this->first($path)); |
||
112 | |||
113 | return $trim ? trim($text) : $text; |
||
114 | } |
||
115 | |||
116 | /* |
||
117 | * Convenience method for getting an attribute of a node |
||
118 | */ |
||
119 | public function attr($attribute) |
||
123 | |||
124 | public function first($path) |
||
131 | |||
132 | /* |
||
133 | * Convenience method for checking if a node exists |
||
134 | */ |
||
135 | public function has($path) |
||
141 | |||
142 | public function el() |
||
146 | |||
147 | /** |
||
148 | * Returns an array of QuiteSimpleXMLElement instances. |
||
149 | * |
||
150 | * @param $path |
||
151 | * @return QuiteSimpleXMLElement[] |
||
152 | */ |
||
153 | public function xpath($path) |
||
159 | |||
160 | /** |
||
161 | * Alias for xpath(). |
||
162 | * |
||
163 | * @param $path |
||
164 | * @return QuiteSimpleXMLElement[] |
||
165 | */ |
||
166 | public function all($path) |
||
170 | |||
171 | /** |
||
172 | * Returns the *untrimmed* text content of the node |
||
173 | */ |
||
174 | public function __toString() |
||
178 | |||
179 | /* The original children and count methods are quite flawed. The count() method |
||
180 | only return the count of children _with no namespace_. The children() method |
||
181 | can take namespace prefix as argument, but doesn't use the document's prefixes, |
||
182 | not the registered ones. |
||
183 | |||
184 | And it returns a "pseudo array" instead of a real iterator... making it quite hard |
||
185 | to work with, there's no next() method for instance... |
||
186 | We're returning a real array instead, even though that might not be what you want |
||
187 | in _all_ situations. |
||
188 | |||
189 | An alternative could be to use xpath('child::node()') |
||
190 | */ |
||
191 | public function children($ns = null) |
||
209 | |||
210 | public function attributes() |
||
226 | |||
227 | /** |
||
228 | * Set the node value |
||
229 | */ |
||
230 | public function setValue($value) |
||
234 | |||
235 | public function asDOMElement() |
||
239 | |||
240 | /** |
||
241 | * Replaces the current node. Thanks to @hakre |
||
242 | * <http://stackoverflow.com/questions/17661167/how-to-replace-xml-node-with-simplexmlelement-php> |
||
243 | */ |
||
244 | public function replace(QuiteSimpleXMLElement $element) |
||
253 | |||
254 | public static function make($input, $ns = array()) |
||
260 | } |
||
261 |