Skip to content

Commit 291e2e0

Browse files
committed
add possibility to register namespaces to DOMXpath
1 parent 5aaa2f6 commit 291e2e0

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/Common/XMLReader.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,25 @@ public function getElements($path, \DOMElement $contextNode = null)
100100
}
101101
}
102102

103+
/**
104+
* Registers the namespace with the DOMXPath object
105+
*
106+
* @param string $prefix The prefix
107+
* @param string $namespaceURI The URI of the namespace
108+
* @return bool true on success or false on failure
109+
* @throws \InvalidArgumentException If called before having loaded the DOM document
110+
*/
111+
public function registerNamespace($prefix, $namespaceURI)
112+
{
113+
if ($this->dom === null) {
114+
throw new \InvalidArgumentException('Dom needs to be loaded before registering a namespace');
115+
}
116+
if ($this->xpath === null) {
117+
$this->xpath = new \DOMXpath($this->dom);
118+
}
119+
return $this->xpath->registerNamespace($prefix, $namespaceURI);
120+
}
121+
103122
/**
104123
* Get element
105124
*

0 commit comments

Comments
 (0)