4 class XPath extends \DOMXPath
15 parent::__construct($doc);
25 if (empty($this->defaultNamespaceURI)) {
28 return self::DEFAULT_NAMESPACE_PREFIX .
':' . $nodeName;
33 $rootElements = $this->getRootElements();
35 if (count($rootElements) !== 1) {
36 throw new \LogicException(
37 sprintf(
'Got %d svg elements, expected exactly one', count($rootElements)),
41 $this->defaultNamespaceURI = (
string)$rootElements[0]->namespaceURI;
43 if ($this->defaultNamespaceURI !==
'') {
44 $this->registerNamespace(self::DEFAULT_NAMESPACE_PREFIX, $this->defaultNamespaceURI);
51 protected function getRootElements()
54 $elements = $this->document->getElementsByTagName(
'svg');
56 foreach ($elements as $element) {
57 if ($element->parentNode !== $this->document) {
60 $rootElements[] = $element;
const DEFAULT_NAMESPACE_PREFIX
__construct(\DOMDocument $doc)
createNodeName($nodeName)