1 | <?php |
||
16 | class SimpleXMLElement |
||
17 | { |
||
18 | use XMLInternalErrorsHelper; |
||
19 | |||
20 | /** @var \SimpleXMLElement Instance of the wrapped SimpleXMLElement object */ |
||
21 | protected $simpleXMLElement; |
||
22 | |||
23 | /** |
||
24 | * Creates a new SimpleXMLElement object |
||
25 | * @see \SimpleXMLElement::__construct |
||
26 | * |
||
27 | * @param string $xmlData A well-formed XML string |
||
28 | * @throws \Box\Spout\Reader\Exception\XMLProcessingException If the XML string is not well-formed |
||
29 | */ |
||
30 | 93 | public function __construct($xmlData) |
|
44 | |||
45 | /** |
||
46 | * Returns the attribute for the given name. |
||
47 | * |
||
48 | * @param string $name Attribute name |
||
49 | * @param string|null|void $namespace An optional namespace for the retrieved attributes |
||
50 | * @return string|null The attribute value or NULL if attribute not found |
||
51 | */ |
||
52 | 84 | public function getAttribute($name, $namespace = null) |
|
60 | |||
61 | /** |
||
62 | * Creates a prefix/ns context for the next XPath query |
||
63 | * @see \SimpleXMLElement::registerXPathNamespace |
||
64 | * |
||
65 | * @param string $prefix The namespace prefix to use in the XPath query for the namespace given in "namespace". |
||
66 | * @param string $namespace The namespace to use for the XPath query. This must match a namespace in |
||
67 | * use by the XML document or the XPath query using "prefix" will not return any results. |
||
68 | * @return bool TRUE on success or FALSE on failure. |
||
69 | */ |
||
70 | 63 | public function registerXPathNamespace($prefix, $namespace) |
|
74 | |||
75 | /** |
||
76 | * Runs XPath query on XML data |
||
77 | * @see \SimpleXMLElement::xpath |
||
78 | * |
||
79 | * @param string $path An XPath path |
||
80 | * @return SimpleXMLElement[]|bool an array of SimpleXMLElement objects or FALSE in case of an error. |
||
81 | */ |
||
82 | 66 | public function xpath($path) |
|
101 | |||
102 | /** |
||
103 | * Wraps the given element into an instance of the wrapper |
||
104 | * |
||
105 | * @param \SimpleXMLElement $element Element to be wrapped |
||
106 | * @return SimpleXMLElement|null The wrapped element or NULL if the given element is invalid |
||
107 | */ |
||
108 | 69 | protected function wrapSimpleXMLElement(\SimpleXMLElement $element) |
|
119 | |||
120 | /** |
||
121 | * Remove all nodes matching the given XPath query. |
||
122 | * It does not map to any \SimpleXMLElement function. |
||
123 | * |
||
124 | * @param string $path An XPath path |
||
125 | * @return void |
||
126 | */ |
||
127 | 66 | public function removeNodesMatchingXPath($path) |
|
135 | |||
136 | /** |
||
137 | * Returns the first child matching the given tag name |
||
138 | * |
||
139 | * @param string $tagName |
||
140 | * @return SimpleXMLElement|null The first child matching the tag name or NULL if none found |
||
141 | */ |
||
142 | 3 | public function getFirstChildByTagName($tagName) |
|
151 | |||
152 | /** |
||
153 | * Returns the immediate children. |
||
154 | * |
||
155 | * @return array The children |
||
156 | */ |
||
157 | public function children() |
||
158 | { |
||
159 | $children = []; |
||
160 | |||
161 | foreach ($this->simpleXMLElement->children() as $child) { |
||
162 | $children[] = $this->wrapSimpleXMLElement($child); |
||
163 | } |
||
164 | |||
165 | return $children; |
||
166 | } |
||
167 | |||
168 | /** |
||
169 | * @return string |
||
170 | */ |
||
171 | 63 | public function __toString() |
|
175 | } |
||
176 |