@@ -72,20 +72,6 @@ public static function createFromDom(DOMDocument $dom): self
7272 return new self (new DOMXPath ($ dom ));
7373 }
7474
75- /**
76- * Add all namespaces automatically.
77- *
78- * @return void
79- */
80- public function registerAllNamespaces ()
81- {
82- foreach ($ this ->xpath ->query ('//namespace::* ' ) ?: [] as $ namespaceNode ) {
83- $ prefix = str_replace ('xmlns: ' , '' , $ namespaceNode ->nodeName );
84- $ namespaceUri = $ namespaceNode ->nodeValue ;
85- $ this ->xpath ->registerNamespace ($ prefix , $ namespaceUri );
86- }
87- }
88-
8975 /**
9076 * Check if namespace exists.
9177 *
@@ -114,15 +100,14 @@ public function getNodeValue(string $expression, $contextNode = null): string
114100 {
115101 $ nodes = $ this ->queryNodes ($ expression , $ contextNode );
116102
117- if (empty ($ nodes )
118- || $ nodes ->length === 0
119- || !($ nodes ->item (0 ) instanceof DOMElement)
120- || !($ nodes ->item (0 ) instanceof DOMNode)
103+ if ($ nodes ->length === 0 ||
104+ !($ nodes ->item (0 ) instanceof DOMElement) ||
105+ !($ nodes ->item (0 ) instanceof DOMNode)
121106 ) {
122107 throw new InvalidXmlException (sprintf ('XML DOM node [%s] not found. ' , $ expression ));
123108 }
124109
125- return $ nodes ->item (0 )->nodeValue ;
110+ return $ nodes ->item (0 )->nodeValue ?? '' ;
126111 }
127112
128113 /**
@@ -134,7 +119,7 @@ public function getNodeValue(string $expression, $contextNode = null): string
134119 *
135120 * @return string|null The node value
136121 */
137- private function findSingleNodeValue (string $ expression , DOMXPath $ xpath , $ contextNode = null )
122+ private function findSingleNodeValue (string $ expression , DOMXPath $ xpath , $ contextNode = null ): ? string
138123 {
139124 if ($ contextNode === null ) {
140125 $ node = $ xpath ->query ($ expression );
@@ -161,14 +146,13 @@ private function findSingleNodeValue(string $expression, DOMXPath $xpath, $conte
161146 *
162147 * @return string|null The node value
163148 */
164- public function findNodeValue (string $ expression , $ contextNode = null )
149+ public function findNodeValue (string $ expression , $ contextNode = null ): ? string
165150 {
166151 $ nodes = $ this ->queryNodes ($ expression , $ contextNode );
167152
168- if (empty ($ nodes )
169- || $ nodes ->length === 0
170- || !($ nodes ->item (0 ) instanceof DOMElement)
171- || !($ nodes ->item (0 ) instanceof DOMNode)
153+ if ($ nodes ->length === 0 ||
154+ !($ nodes ->item (0 ) instanceof DOMElement) ||
155+ !($ nodes ->item (0 ) instanceof DOMNode)
172156 ) {
173157 return null ;
174158 }
@@ -190,7 +174,7 @@ public function getAttributeValue(string $expression, $contextNode = null): stri
190174 {
191175 $ nodes = $ this ->queryNodes ($ expression , $ contextNode );
192176
193- if (empty ( $ nodes) || $ nodes ->length === 0 || !( $ nodes instanceof DOMNodeList) ) {
177+ if ($ nodes ->length === 0 ) {
194178 throw new InvalidXmlException (sprintf ('XML DOM attribute [%s] not found. ' , $ expression ));
195179 }
196180
@@ -199,7 +183,7 @@ public function getAttributeValue(string $expression, $contextNode = null): stri
199183 throw new InvalidXmlException (sprintf ('XML DOM attribute [%s] not found. ' , $ expression ));
200184 }
201185
202- return $ attribute ->nodeValue ;
186+ return $ attribute ->nodeValue ?? '' ;
203187 }
204188
205189 /**
0 commit comments