Extract #defines and anonymous enumerations.
@param \DOMDocument $document
@param string $namespace
484357
private function ExtractConstants(\DOMDocument $document, $namespace = "")
    {
        $xpath = new DOMXPath($document);

        $entries = $xpath->evaluate(
            "//compound[@kind='file'] | //compound[@kind='namespace']", 
            $document
        );

        for($i = 0; $i < $entries->length; $i++)
        {
            $kind = $entries->item($i)->getAttribute("kind");
            $refid = $entries->item($i)->getAttribute("refid");
            $name = $entries->item($i)->childNodes->item(0)->nodeValue;

            if($kind == "namespace")
                $namespace = str_replace("::", "\\", $name);
            else
                $namespace = "\\";

            $file_doc = new DOMDocument();
            $file_doc->load($this->definitions_path . "/$refid.xml");

            $file_xpath = new DOMXPath($file_doc);

            $file_members = $file_xpath->evaluate(
                "//memberdef[@kind='define'] | //memberdef[@kind='enum']", 
                $file_doc
            );

            for($member = 0; $member < $file_members->length; $member++)
            {
                $kind = $file_members->item($member)->getAttribute("kind");

                $location = str_replace(
                    $this->headers_path, 
                    "", 
                    str_replace(
                        "\\", 
                        "/", 
                        $file_xpath->evaluate(
                            "location", 
                            $file_members->item($member)
                        )->item(0)->getAttribute("file")
                    )
                );

                if($kind == "define")
                {
                    $define_name = $file_xpath->evaluate(
                        "name", 
                        $file_members->item($member)
                    )->item(0)->nodeValue;
                    
                    $define_description = $file_xpath->evaluate(
                        "briefdescription", 
                        $file_members->item($member)
                    )->item(0)->nodeValue;

                    $define_initializer = true;

                    if(is_object($file_xpath->evaluate("initializer", $file_members->item($member))->item(0)))
                        $define_initializer = $file_xpath->evaluate(
                            "initializer", 
                            $file_members->item($member)
                        )->item(0)->nodeValue;
                    
                    else
                        $this->SendMessage(
                            t("Warning:") . " " 
                            . t("no initializer value for") 
                            . " #" . $define_name 
                        );

                    // Skip macro function defines
                    if($file_xpath->evaluate("param", $file_members->item($member))->length > 0)
                    {
                        continue;
                    }

                    // Skip defines used for compiler
                    if($define_name{0} == "_" && $define_name{1} == "_")
                    {
                        continue;
                    }

                    $constant = new \Peg\Lib\Definitions\Element\Constant(
                        $define_name,
                        $define_initializer,
                        $define_description
                    );
                    
                    $this->symbols->AddConstant(
                        $constant, 
                        $location, 
                        $namespace
                    );
                }

                // Also add anonymous enumerations as constants
                elseif($kind == "enum")
                {
                    $enum_name = $file_xpath->evaluate(
                        "name", 
                        $file_members->item($member)
                    )->item(0)->nodeValue;
                    
                    $enum_description = $file_xpath->evaluate(
                        "briefdescription", 
                        $file_members->item($member)
                    )->item(0)->nodeValue;

                    // Skip non anonymous enumerations
                    if($enum_name{0} != "@")
                        continue;

                    $enum_values = $file_xpath->evaluate(
                        "enumvalue", 
                        $file_members->item($member)
                    );

                    for($enum_value = 0; $enum_value < $enum_values->length; $enum_value++)
                    {
                        $enum_option = $file_xpath->evaluate(
                            "name", 
                            $enum_values->item($enum_value)
                        )->item(0)->nodeValue;
                        
                        $constant = new \Peg\Lib\Definitions\Element\Constant(
                            $enum_option,
                            1,
                            $enum_description
                        );

                        $this->symbols->AddConstant(
                            $constant, 
                            $location, 
                            $namespace
                        );
                    }
                }
            }
        }
    }
900851
protected function validateNamespace($namespace)
    {
        switch ($namespace) {
            case 'ns:DNS':
                return Uuid::NAMESPACE_DNS;
                break;
            case 'ns:URL':
                return Uuid::NAMESPACE_URL;
                break;
            case 'ns:OID':
                return Uuid::NAMESPACE_OID;
                break;
            case 'ns:X500':
                return Uuid::NAMESPACE_X500;
                break;
        }

        if (Uuid::isValid($namespace)) {
            return $namespace;
        }

        throw new Exception(
            'Invalid namespace. '
            . 'May be either a UUID in string representation or an identifier '
            . 'for internally pre-defined namespace UUIDs (currently known '
            . 'are "ns:DNS", "ns:URL", "ns:OID", and "ns:X500").'
        );
    }
927569
private function removeNonSatNSNode(string $namespace)
    {
        foreach ($this->dom()->getElementsByTagNameNS($namespace, '*') as $children) {
            $children->parentNode->removeChild($children);
        }
    }
1019017
protected static function _namespaceIsset($namespace, $name = null)
    {
        if (self::$_readable === false) {
            /**
             * @see Zend_Session_Exception
             */
            require_once 'Zend/Session/Exception.php';
            throw new Zend_Session_Exception(self::_THROW_NOT_READABLE_MSG);
        }

        if ($name === null) {
            return ( isset($_SESSION[$namespace]) || isset(self::$_expiringData[$namespace]) );
        } else {
            return ( isset($_SESSION[$namespace][$name]) || isset(self::$_expiringData[$namespace][$name]) );
        }
    }
252233
public function insert($namespace, $document)
    {
        $bulk = new BulkWrite();

        $bulk->insert($document);

        return $this->bulkWrite($namespace, $bulk)->getInsertedCount();
    }
1343345
public function RemoveEnumeration($name, $namespace="", $header="")
    {
        if($header)
        {
            if($namespace)
            {
                unset($this->headers[$header]->namespaces[$namespace]->enumerations[$name]);
            }
            else
            {
                foreach($this->headers[$header]->namespaces as $namespace_object)
                {
                    unset($namespace_object->enumerations[$name]);
                }
            }
        }
        elseif($namespace)
        {
            foreach($this->headers as $header_object)
            {
                unset($header_object->namespaces[$namespace]->enumerations[$name]);
            }
        }
        else
        {
            foreach($this->headers as $header_object)
            {
                foreach($header_object->namespaces as $namespace_object)
                {
                    unset($namespace_object->enumerations[$name]);
                }
            }
        }
    }
1267675
protected function encodeLiteral(DOMDocument $document)
    {
        $xpath = new DOMXPath($document);

        $xpathExpression = '//literal[not(@class="html")]';

        $elements = $xpath->query($xpathExpression);

        foreach ($elements as $element) {
            $element->textContent = str_replace(']]>', ']]]]><![CDATA[>', $element->textContent);
        }
    }
895555
public function convert(DOMDocument $document)
    {
        $document = clone $document;

        $xpath = new DOMXPath($document);
        $xpath->registerNamespace('docbook', 'http://docbook.org/ns/docbook');
        $xpath->registerNamespace('xlink', 'http://www.w3.org/1999/xlink');

        $linkAttributeExpression = "starts-with( @xlink:href, 'ezlocation://' ) or starts-with( @xlink:href, 'ezcontent://' )";
        $xpathExpression = "//docbook:link[{$linkAttributeExpression}]|//docbook:ezlink";

        /** @var \DOMElement $link */
        foreach ($xpath->query($xpathExpression) as $link) {
            // Set resolved href to number character as a default if it can't be resolved
            $hrefResolved = '#';
            $href = $link->getAttribute('xlink:href');
            $location = null;
            preg_match('~^(.+://)?([^#]*)?(#.*|\\s*)?$~', $href, $matches);
            list(, $scheme, $id, $fragment) = $matches;

            if ($scheme === 'ezcontent://') {
                try {
                    $contentInfo = $this->contentService->loadContentInfo($id);
                    $location = $this->locationService->loadLocation($contentInfo->mainLocationId);
                    $hrefResolved = $this->urlAliasRouter->generate($location) . $fragment;
                } catch (APINotFoundException $e) {
                    if ($this->logger) {
                        $this->logger->warning(
                            'While generating links for richtext, could not locate ' .
                            'Content object with ID ' . $id
                        );
                    }
                } catch (APIUnauthorizedException $e) {
                    if ($this->logger) {
                        $this->logger->notice(
                            'While generating links for richtext, unauthorized to load ' .
                            'Content object with ID ' . $id
                        );
                    }
                }
            } elseif ($scheme === 'ezlocation://') {
                try {
                    $location = $this->locationService->loadLocation($id);
                    $hrefResolved = $this->urlAliasRouter->generate($location) . $fragment;
                } catch (APINotFoundException $e) {
                    if ($this->logger) {
                        $this->logger->warning(
                            'While generating links for richtext, could not locate ' .
                            'Location with ID ' . $id
                        );
                    }
                } catch (APIUnauthorizedException $e) {
                    if ($this->logger) {
                        $this->logger->notice(
                            'While generating links for richtext, unauthorized to load ' .
                            'Location with ID ' . $id
                        );
                    }
                }
            } else {
                $hrefResolved = $href;
            }

            $hrefAttributeName = 'xlink:href';

            // For embeds set the resolved href to the separate attribute
            // Original href needs to be preserved in order to generate link parameters
            // This will need to change with introduction of UrlService and removal of URL link
            // resolving in external storage
            if ($link->localName === 'ezlink') {
                $hrefAttributeName = 'href_resolved';
            }

            $link->setAttribute($hrefAttributeName, $hrefResolved);
        }

        return $document;
    }
467517
private function loadModuleAnnotations($namespace)
    {
        $this->loader->loadModuleAnnotations($namespace, function($fileNamespace){
            $this->parser->parse($fileNamespace);
            $this->parser->execParse($fileNamespace);
        });
    }
526530
public static function getAllElementsByXpath($node, $xpath_query, $namespaces = array())
    {
        if(is_a($node, 'DOMDocument'))
        {
            $xpath = new DOMXPath($node);
        }
        elseif(is_a($node, 'DOMNode'))
        {
            $xpath = new DOMXPath($node->ownerDocument);
        }
        else
        {
            return null;
        }

        foreach($namespaces as $prefix => $namespaceURI)
        {
            $xpath->registerNamespace($prefix, $namespaceURI);
        }

        $node_list = $xpath->query($xpath_query, $node);

        return $node_list;
    }
772898
public function getNamespaces(\DOMElement $element = null)
    {
        if ($this->xpath === null) {
            $this->xpath = new \DOMXPath($this);
        }

        if ($element === null) {
            $nodes = $this->xpath->query('namespace::*');
        } else {
            $nodes = $this->xpath->query('namespace::*', $element);
        }

        $ns = array();

        if ($nodes) {
            foreach ($nodes as $node) {
                $arr = $element->getAttribute($node->nodeName);

                if ($arr) {
                    $ns[$node->nodeName] = $arr;
                }
            }

            $nodes = null;
        }

        return $ns;
    }
583424
public function deregisterDocument($document)
    {
        $oid = $this->getObjectIdentifier($document);
        $this->assertDocumentExists($document);
        $nodeIdentifier = $this->documentNodeMap[$oid];
        $locale = $this->documentLocaleMap[$oid];

        unset($this->nodeMap[$nodeIdentifier]);
        unset($this->nodeDocumentMap[$this->getNodeLocaleKey($nodeIdentifier, $locale)]);
        unset($this->documentMap[$oid]);
        unset($this->documentNodeMap[$oid]);
        unset($this->documentLocaleMap[$oid]);
        unset($this->hydrationState[$oid]);
    }
391683
static public function build( XML_DOM_Node $tree, $encoding = "utf-8", $namespaces = array() )
	{
		$document	= new DOMDocument( "1.0", $encoding );
		$document->formatOutput = TRUE;
		$root		= $document->createElement( $tree->getNodename() );
		foreach( $namespaces as $prefix => $namespace )
			$root->setAttribute( "xmlns:".$prefix, $namespace );
		$root		= $document->appendChild( $root );
		self::buildRecursive( $document, $root, $tree, $encoding );
		return $document->saveXML();
	}
780596
protected function addXmlElement(\DOMNode $parentNode, string $nodeName, string $namespace): \DOMNode
    {
        $node = $parentNode->appendChild(
            ($parentNode->ownerDocument ?? $parentNode)->createElementNS($namespace, $nodeName)
        );

        return $node;
    }
1258650
private function createNumberNode(\DOMDocument $document, $value, string $name = null): \DOMNode
    {
        $node = $document->createElement('json:number', (string) $value);

        if (null !== $name) {
            $node->setAttribute('name', $name);
        }

        return $node;
    }
932822
function (namespace) {
			var result,
				aNamespaceParts = namespace.split(".");

			if (aNamespaceParts[0] === "Org" && aNamespaceParts[1] === "OData") {
				result = '<a href="' + this.ANNOTATIONS_NAMESPACE_LINK + namespace + '.xml">' + namespace + '</a>';
			} else {
				result = namespace;
			}

			result = this._preProcessLinksInTextBlock(result);
			return result;
		}
121470
public static function delete(string $name, string $namespace = '*'): void
    {
        self::initialize();
        if (isset($_SESSION[$namespace][$name])) {
            unset($_SESSION[$namespace][$name]);
            if (count($_SESSION[$namespace]) === 0) {
                unset($_SESSION[$namespace]);
            }
        }
    }