44
55namespace SimpleSAML \XMLSecurity \Utils ;
66
7- use DOMDocument ;
8- use DOMElement ;
97use DOMNode ;
108use DOMXPath ;
119use SimpleSAML \XMLSecurity \Constants as C ;
12- use SimpleSAML \XMLSecurity \Exception \RuntimeException ;
1310use SimpleSAML \XPath \XPath as XPathUtils ;
1411
1512/**
@@ -23,38 +20,18 @@ class XPath extends XPathUtils
2320 * Get a DOMXPath object that can be used to search for XMLDSIG elements.
2421 *
2522 * @param \DOMNode $node The document to associate to the DOMXPath object.
23+ * @param bool $autoregister Whether to auto-register all namespaces used in the document
2624 *
2725 * @return \DOMXPath A DOMXPath object ready to use in the given document, with the XMLDSIG namespace already
2826 * registered.
2927 */
30- public static function getXPath (DOMNode $ node ): DOMXPath
28+ public static function getXPath (DOMNode $ node, bool $ autoregister = false ): DOMXPath
3129 {
32- $ xp = parent ::getXPath ($ node );
30+ $ xp = parent ::getXPath ($ node , $ autoregister );
31+
3332 $ xp ->registerNamespace ('ds ' , C::NS_XDSIG );
3433 $ xp ->registerNamespace ('xenc ' , C::NS_XENC );
35- return $ xp ;
36- }
37-
3834
39- /**
40- * Search for an element with a certain name among the children of a reference element.
41- *
42- * @param \DOMNode $ref The DOMDocument or DOMElement where encrypted data is expected to be found as a child.
43- * @param string $name The name (possibly prefixed) of the element we are looking for.
44- *
45- * @return \DOMElement|false The element we are looking for, or false when not found.
46- *
47- * @throws \SimpleSAML\XMLSecurity\Exception\RuntimeException If no DOM document is available.
48- */
49- public static function findElement (DOMNode $ ref , string $ name ): DOMElement |false
50- {
51- $ doc = $ ref instanceof DOMDocument ? $ ref : $ ref ->ownerDocument ;
52- if ($ doc === null ) {
53- throw new RuntimeException ('Cannot search, no DOMDocument available ' );
54- }
55-
56- $ nodeset = self ::getXPath ($ doc )->query ('./ ' . $ name , $ ref );
57-
58- return $ nodeset ->item (0 ) ?? false ;
35+ return $ xp ;
5936 }
6037}
0 commit comments