1 | <?php |
||
49 | class QuiteSimpleXMLElement |
||
50 | { |
||
51 | use HelperMethods; |
||
52 | |||
53 | /** |
||
54 | * @var array |
||
55 | */ |
||
56 | public $namespaces; |
||
57 | |||
58 | /** |
||
59 | * @var SimpleXMLElement |
||
60 | */ |
||
61 | public $el; |
||
62 | |||
63 | /** |
||
64 | * QuiteSimpleXMLElement constructor. |
||
65 | * |
||
66 | * @param string|SimpleXMLElement|QuiteSimpleXMLElement $elem |
||
67 | * @param QuiteSimpleXMLElement $inherit_from |
||
68 | * @throws InvalidXMLException |
||
69 | * @throws InvalidArgumentException |
||
70 | */ |
||
71 | public function __construct($elem, QuiteSimpleXMLElement $inherit_from = null) |
||
88 | |||
89 | /** |
||
90 | * Internal helper method to get a SimpleXMLElement from either a string |
||
91 | * or a SimpleXMLElement/QuiteSimpleXMLElement object. |
||
92 | * |
||
93 | * @param string|SimpleXMLElement|QuiteSimpleXMLElement $elem |
||
94 | * @return SimpleXMLElement |
||
95 | * @throws InvalidXMLException |
||
96 | * @throws InvalidArgumentException |
||
97 | */ |
||
98 | private function getSimpleXMLElement($elem) |
||
108 | |||
109 | /** |
||
110 | * Internal helper method to parse content from string. |
||
111 | * |
||
112 | * @param string $content |
||
113 | * @return SimpleXMLElement |
||
114 | */ |
||
115 | private function initFromString($content) |
||
123 | |||
124 | /** |
||
125 | * Internal helper method to parse content from string. |
||
126 | * |
||
127 | * @param $elem |
||
128 | * @return SimpleXMLElement |
||
129 | */ |
||
130 | private function initFromObject($elem) |
||
139 | |||
140 | /** |
||
141 | * Register a new xpath namespace. |
||
142 | * |
||
143 | * @param string $prefix |
||
144 | * @param string $uri |
||
145 | */ |
||
146 | public function registerXPathNamespace($prefix, $uri) |
||
151 | |||
152 | /** |
||
153 | * Register an array of new xpath namespaces. |
||
154 | * |
||
155 | * @param array $namespaces |
||
156 | */ |
||
157 | public function registerXPathNamespaces($namespaces) |
||
164 | |||
165 | /** |
||
166 | * Get the text of the first node matching an XPath query. By default, |
||
167 | * the text will be trimmed, but if you want the untrimmed text, set |
||
168 | * the second paramter to False. |
||
169 | * |
||
170 | * @param string $path |
||
171 | * @param bool $trim |
||
172 | * @return string |
||
173 | */ |
||
174 | public function text($path='.', $trim=true) |
||
180 | |||
181 | /** |
||
182 | * Get the wrapped SimpleXMLElement object. |
||
183 | * |
||
184 | * @return SimpleXMLElement |
||
185 | */ |
||
186 | public function el() |
||
190 | |||
191 | /** |
||
192 | * Returns the *untrimmed* text content of the node. |
||
193 | * @return string |
||
194 | */ |
||
195 | public function __toString() |
||
199 | |||
200 | /** |
||
201 | * Returns the child elements. |
||
202 | * |
||
203 | * Note: By default, only children without namespace will be returned. You can |
||
204 | * specify a namespace prefix to get children with that namespace prefix. |
||
205 | * |
||
206 | * Tip: You could also use `xpath('child::node()')`. |
||
207 | * |
||
208 | * @param null $ns |
||
209 | * @return QuiteSimpleXMLElement[] |
||
210 | */ |
||
211 | public function children($ns=null) |
||
224 | |||
225 | /** |
||
226 | * Returns the number of child elements. |
||
227 | * |
||
228 | * Note: By default, only children without namespace will be counted. You can |
||
229 | * specify a namespace prefix to count children with that namespace prefix. |
||
230 | * |
||
231 | * @param null $ns |
||
232 | * @return int |
||
233 | */ |
||
234 | public function count($ns = null) |
||
238 | |||
239 | /** |
||
240 | * Returns and element's attributes. |
||
241 | * |
||
242 | * @return SimpleXMLElement a `SimpleXMLElement` object that can be |
||
243 | * iterated over to loop through the attributes on the tag. |
||
244 | */ |
||
245 | public function attributes() |
||
249 | |||
250 | /** |
||
251 | * Returns the XML as text. |
||
252 | * |
||
253 | * @return string |
||
254 | */ |
||
255 | public function asXML() |
||
259 | |||
260 | /** |
||
261 | * Get the element name. |
||
262 | * |
||
263 | * @return string |
||
264 | */ |
||
265 | public function getName() |
||
269 | |||
270 | /** |
||
271 | * Return a namespace array. |
||
272 | * |
||
273 | * @return array |
||
274 | */ |
||
275 | public function getNamespaces() |
||
279 | |||
280 | /** |
||
281 | * Set the node value. |
||
282 | * |
||
283 | * @param string $value |
||
284 | */ |
||
285 | public function setValue($value) |
||
289 | |||
290 | /** |
||
291 | * Return the current object as DOMElement. |
||
292 | * |
||
293 | * @return \DOMElement |
||
294 | */ |
||
295 | public function asDOMElement() |
||
299 | |||
300 | /** |
||
301 | * Replaces the current node. Thanks to @hakre |
||
302 | * <http://stackoverflow.com/questions/17661167/how-to-replace-xml-node-with-simplexmlelement-php>. |
||
303 | * |
||
304 | * @param QuiteSimpleXMLElement $element |
||
305 | */ |
||
306 | public function replace(QuiteSimpleXMLElement $element) |
||
315 | |||
316 | /** |
||
317 | * Static helper method to make initialization easier. |
||
318 | * |
||
319 | * @param $input |
||
320 | * @param array $ns |
||
321 | * @return QuiteSimpleXMLElement |
||
322 | */ |
||
323 | public static function make($input, $ns = []) |
||
330 | } |
||
331 |