public function setNamespace($namespace) { $node = $this->contextNode->getElementsByTagNameNS('http://schema.phpunit.de/coverage/1.0', 'namespace')->item(0); if (!$node) { $node = $this->contextNode->appendChild($this->contextNode->ownerDocument->createElementNS('http://schema.phpunit.de/coverage/1.0', 'namespace')); } $node->setAttribute('name', $namespace); }
public function getLineCoverage($line) { $coverage = $this->contextNode->getElementsByTagNameNS('http://schema.phpunit.de/coverage/1.0', 'coverage')->item(0); if (!$coverage) { $coverage = $this->contextNode->appendChild($this->dom->createElementNS('http://schema.phpunit.de/coverage/1.0', 'coverage')); } $lineNode = $coverage->appendChild($this->dom->createElementNS('http://schema.phpunit.de/coverage/1.0', 'line')); return new PHP_CodeCoverage_Report_XML_File_Coverage($lineNode, $line); }
public function getHrefs($locatorLabel) { if (is_null($this->locations)) { $locations = array(); $results = $this->element->getElementsByTagNameNS('http://www.xbrl.org/2003/linkbase', 'loc'); /** @var $result \DOMElement */ foreach ($results as $result) { $label = $result->getAttributeNS('http://www.w3.org/1999/xlink', 'label'); $locations[$label] = empty($locations[$label]) ? array() : $locations[$label]; $locations[$label][] = $this->linkBase->getConceptId($result->getAttributeNS('http://www.w3.org/1999/xlink', 'href')); } $this->locations = $locations; } return $this->locations[$locatorLabel]; }
protected function assertPropertyExists($exptectedNs, $expectedName, array $expectedProperties, DOMElement $actualParent) { $props = $actualParent->getElementsByTagNameNS($exptectedNs, $expectedName); $this->assertEquals(1, $props->length); $prop = $props->item(0); foreach ($expectedProperties as $propDef) { $this->assertTrue($prop->hasAttributeNs($propDef[0], $propDef[1])); } }
/** * Inserts $imageData as a child into $imageObject. * * Detects if $imageObject contains <office:binary-data/>. If this is the case, * this element is replaced with the given $imageData. Otherwise, * $imageData is added as a new child. * * @param DOMElement $imageObject * @param DOMElement $imageData */ protected function insertImageData($imageObject, $imageData) { $binaryDataElems = $imageObject->getElementsByTagNameNS(ezcDocumentOdt::NS_ODT_OFFICE, 'binary-data'); if ($binaryDataElems->length === 1) { $imageObject->replaceChild($imageData, $binaryDataElems->item(0)); } else { $imageObject->appendChild($imageData); } }
public static function unserialize(\DOMElement $dom) { $principals = array(); $xhrefs = $dom->getElementsByTagNameNS('urn:DAV', 'href'); for ($ii = 0; $ii < $xhrefs->length; $ii++) { $principals[] = $xhrefs->item($ii)->textContent; } return new self($principals); }
protected function _process(DOMElement $root) { foreach ($root->getElementsByTagNameNS($this->_acNS, '*') as $element) { /* @var $element Ajde_Template_Parser_Xhtml_Element */ if ($element->inACNameSpace()) { $element->processComponent($this); } elseif ($element->inAVNameSpace()) { $element->processVariable($this); } } return $root; }
/** * Unserializes the {DAV:}acl xml element. * * @param \DOMElement $dom * @param array $propertyMap * @return Acl */ static function unserialize(\DOMElement $dom, array $propertyMap) { $privileges = []; $xaces = $dom->getElementsByTagNameNS('urn:DAV', 'ace'); for ($ii = 0; $ii < $xaces->length; $ii++) { $xace = $xaces->item($ii); $principal = $xace->getElementsByTagNameNS('urn:DAV', 'principal'); if ($principal->length !== 1) { throw new DAV\Exception\BadRequest('Each {DAV:}ace element must have one {DAV:}principal element'); } $principal = Principal::unserialize($principal->item(0), $propertyMap); switch ($principal->getType()) { case Principal::HREF: $principal = $principal->getHref(); break; case Principal::AUTHENTICATED: $principal = '{DAV:}authenticated'; break; case Principal::UNAUTHENTICATED: $principal = '{DAV:}unauthenticated'; break; case Principal::ALL: $principal = '{DAV:}all'; break; } $protected = false; if ($xace->getElementsByTagNameNS('urn:DAV', 'protected')->length > 0) { $protected = true; } $grants = $xace->getElementsByTagNameNS('urn:DAV', 'grant'); if ($grants->length < 1) { throw new DAV\Exception\NotImplemented('Every {DAV:}ace element must have a {DAV:}grant element. {DAV:}deny is not yet supported'); } $grant = $grants->item(0); $xprivs = $grant->getElementsByTagNameNS('urn:DAV', 'privilege'); for ($jj = 0; $jj < $xprivs->length; $jj++) { $xpriv = $xprivs->item($jj); $privilegeName = null; for ($kk = 0; $kk < $xpriv->childNodes->length; $kk++) { $childNode = $xpriv->childNodes->item($kk); if ($t = DAV\XMLUtil::toClarkNotation($childNode)) { $privilegeName = $t; break; } } if (is_null($privilegeName)) { throw new DAV\Exception\BadRequest('{DAV:}privilege elements must have a privilege element contained within them.'); } $privileges[] = ['principal' => $principal, 'protected' => $protected, 'privilege' => $privilegeName]; } } return new self($privileges); }
function getElement(DOMElement $parent, $tagname, $ns = NULL) { if ($ns !== NULL) { $el = $parent->getElementsByTagNameNS($ns, preg_replace('/^.*:/', '', $tagname))->item(0); } else { $el = $parent->getElementsByTagName($tagname)->item(0); } if (!$el) { $el = $parent->ownerDocument->createElementNS($ns, $tagname); $parent->appendChild($el); newline($parent); } return $el; }
/** * Filter a single element. * * @param DOMElement $element * @return void */ public function filterElement(DOMElement $element) { $element->setProperty('type', 'footnote'); $citations = $element->getElementsByTagNameNS(ezcDocumentOdt::NS_ODT_TEXT, 'note-citation'); // Should be only 1, foreach to remove all foreach ($citations as $cite) { $attrs = $element->getProperty('attributes'); if ($attrs === false) { $attrs = array(); } $attrs['label'] = $cite->nodeValue; $element->setProperty('attributes', $attrs); $element->removeChild($cite); } }
/** * Unserializes the {DAV:}current-user-privilege-set element. * * @param DOMElement $node * @return CurrentUserPrivilegeSet */ public static function unserialize(\DOMElement $node) { $result = array(); $xprivs = $node->getElementsByTagNameNS('urn:DAV', 'privilege'); for ($jj = 0; $jj < $xprivs->length; $jj++) { $xpriv = $xprivs->item($jj); $privilegeName = null; for ($kk = 0; $kk < $xpriv->childNodes->length; $kk++) { $childNode = $xpriv->childNodes->item($kk); if ($t = DAV\XMLUtil::toClarkNotation($childNode)) { $privilegeName = $t; break; } } $result[] = $privilegeName; } return new self($result); }
/** * Unserializes the {DAV:}acl xml element. * * @param DOMElement $dom * @return Sabre_DAVACL_Property_Acl */ public static function unserialize(DOMElement $dom) { $privileges = array(); $xaces = $dom->getElementsByTagNameNS('urn:DAV', 'ace'); for ($ii = 0; $ii < $xaces->length; $ii++) { $xace = $xaces->item($ii); $principal = $xace->getElementsByTagNameNS('urn:DAV', 'principal'); if ($principal->length !== 1) { throw new Sabre_DAV_Exception_BadRequest('Each {DAV:}ace element must have one {DAV:}principal element'); } $principal = Sabre_DAVACL_Property_Principal::unserialize($principal->item(0)); if ($principal->getType() !== Sabre_DAVACL_Property_Principal::HREF) { throw new Sabre_DAV_Exception_NotImplemented('Currently only uri based principals are support, {DAV:}all, {DAV:}unauthenticated and {DAV:}authenticated are not implemented yet'); } $principal = $principal->getHref(); $protected = false; if ($xace->getElementsByTagNameNS('urn:DAV', 'protected')->length > 0) { $protected = true; } $grants = $xace->getElementsByTagNameNS('urn:DAV', 'grant'); if ($grants->length < 1) { throw new Sabre_DAV_Exception_NotImplemented('Every {DAV:}ace element must have a {DAV:}grant element. {DAV:}deny is not yet supported'); } $grant = $grants->item(0); $xprivs = $grant->getElementsByTagNameNS('urn:DAV', 'privilege'); for ($jj = 0; $jj < $xprivs->length; $jj++) { $xpriv = $xprivs->item($jj); $privilegeName = null; for ($kk = 0; $kk < $xpriv->childNodes->length; $kk++) { $childNode = $xpriv->childNodes->item($kk); if ($t = Sabre_DAV_XMLUtil::toClarkNotation($childNode)) { $privilegeName = $t; break; } } if (is_null($privilegeName)) { throw new Sabre_DAV_Exception_BadRequest('{DAV:}privilege elements must have a privilege element contained within them.'); } $privileges[] = array('principal' => $principal, 'protected' => $protected, 'privilege' => $privilegeName); } } return new self($privileges); }
/** * @inheritdoc */ public static function fromXml(\DOMElement $element, array $xmlNamespaces = array()) { $value = array(); foreach ($element->getElementsByTagNameNS('DAV:', 'lockentry') as $xEntry) { $locktype = null; $lockscope = null; // search for WebDAV XML elements $types = $xEntry->getElementsByTagNameNS('DAV:', 'locktype'); $scopes = $xEntry->getElementsByTagNameNS('DAV:', 'lockscope'); if ($types->length > 0 && $scopes->length > 0) { $locktype = $types->item(0)->hasChildNodes() ? $types->item(0)->firstChild->localName : null; $lockscope = $scopes->item(0)->hasChildNodes() ? $scopes->item(0)->firstChild->localName : null; } if ($locktype && $lockscope) { if (!isset($value[$locktype])) { $value[$locktype] = array(); } $value[$locktype][] = $lockscope; } } return new self($value); }
public function getChildAttribute(\DOMElement $node) { $name = $node->getAttributeNS($this->namespaces['sv'], 'name'); $type = strtolower($node->getAttributeNS($this->namespaces['sv'], 'type')); $values = array(); if ($name == 'jcr:created') { $values[] = date(self::DATEFORMAT); } else { foreach ($node->getElementsByTagNameNS($this->namespaces['sv'], 'value') as $nodeValue) { $values[] = $nodeValue->nodeValue; } } $isMultiValue = false; if ($name == 'jcr:mixinTypes' || count($values) > 1 || $node->hasAttributeNS($this->namespaces['sv'], 'multiple') && $node->getAttributeNS($this->namespaces['sv'], 'multiple') == 'true') { $isMultiValue = true; } return array($name, array('type' => $type, 'value' => $values, 'multiValued' => $isMultiValue)); }
/** * {@inheritdoc} */ protected function parseRoute(RouteCollection $collection, \DOMElement $node, $path) { if ($this->includeFormat) { $path = $node->getAttribute('path'); // append format placeholder if not present if (false === strpos($path, '{_format}')) { $node->setAttribute('path', $path . '.{_format}'); } // set format requirement if configured globally $requirements = $node->getElementsByTagNameNS(self::NAMESPACE_URI, 'requirement'); $format = null; for ($i = 0; $i < $requirements->length; ++$i) { $item = $requirements->item($i); if ($item instanceof \DOMElement && $item->hasAttribute('_format')) { $format = $item->getAttribute('_format'); break; } } if (null === $format && !empty($this->formats)) { $requirement = $node->ownerDocument->createElementNs(self::NAMESPACE_URI, 'requirement', implode('|', array_keys($this->formats))); $requirement->setAttribute('key', '_format'); $node->appendChild($requirement); } } // set the default format if configured if (null !== $this->defaultFormat) { $defaultFormatNode = $node->ownerDocument->createElementNS(self::NAMESPACE_URI, 'default', $this->defaultFormat); $defaultFormatNode->setAttribute('key', '_format'); $node->appendChild($defaultFormatNode); } $options = $this->getOptions($node); foreach ($options as $option) { $node->appendChild($option); } $length = $node->childNodes->length; for ($i = 0; $i < $length; ++$i) { $loopNode = $node->childNodes->item($i); if ($loopNode->nodeType == XML_TEXT_NODE) { continue; } $newNode = $node->ownerDocument->createElementNS(self::NAMESPACE_URI, $loopNode->nodeName, $loopNode->nodeValue); foreach ($loopNode->attributes as $value) { $newNode->setAttribute($value->name, $value->value); } $node->appendChild($newNode); } parent::parseRoute($collection, $node, $path); }
public function import_organization_items(DOMElement &$node, cc_i_manifest &$doc) { if (is_null($this->organizations)) { $this->organizations = array(); } $nlist = $node->getElementsByTagNameNS($this->ccnamespaces['imscc'], 'organization'); if (is_object($nlist)) { foreach ($nlist as $nd) { $sc = new cc_organization($nd, $doc); $this->organizations[$sc->identifier] = $sc; } } }
/** * Get the first atom link attribute with a specified rel= value. * * @param string $rel The value of rel= we seek to find. * @return DOMElement The atom link attribute matching the rel value, * else null if there is no match. **/ function getLink($rel) { $list = $this->model->getElementsByTagNameNS(_GSC_Ns::atom, 'link'); $count = $list->length; for ($pos = 0; $pos < $count; $pos++) { $child = $list->item($pos); if ($child->getAttribute('rel') == $rel) { return $child; } } return null; }
/** * Parses the XML element $node and creates a feed element in the current * module with name $name. * * @param string $name The name of the element belonging to the module * @param DOMElement $node The XML child from which to take the values for $name */ public function parse($name, DOMElement $node) { if ($name === 'new-feed-url') { $name = 'newfeedurl'; } if ($this->isElementAllowed($name)) { $element = $this->add($name); $value = $node->textContent; switch ($name) { case 'category': foreach ($node->childNodes as $subNode) { if (get_class($subNode) === 'DOMElement') { $subCategory = $element->add($name); if ($subNode->hasAttribute('text')) { $subCategory->term = $subNode->getAttribute('text'); } } } if ($node->hasAttribute('text')) { $element->term = $node->getAttribute('text'); } break; case 'image': // no textContent in $node if ($node->hasAttribute('href')) { $element->link = $node->getAttribute('href'); } break; case 'newfeedurl': $element->href = $node->textContent; break; case 'owner': $namespace = self::getNamespace(); $nodes = $node->getElementsByTagNameNS($namespace, 'email'); if ($nodes->length >= 1) { $element->email = $nodes->item(0)->textContent; } $nodes = $node->getElementsByTagNameNS($namespace, 'name'); if ($nodes->length >= 1) { $element->name = $nodes->item(0)->textContent; } break; case 'author': $element->name = $value; break; default: $element->text = $value; } } }
/** * Extracts the <lockentry /> XML elements. * * This method extracts the <lockentry /> XML elements from the <supportedlock /> * element and returns the corresponding * ezcWebdavSupportedLockPropertyLockentry object to be used as the content * of ezcWebdavSupportedLockProperty. * * @param DOMElement $domElement * @return ezcWebdavSupportedLockProperty */ protected function extractLockEntryContent(DOMElement $domElement) { return new ezcWebdavSupportedLockPropertyLockentry($domElement->getElementsByTagNameNS(ezcWebdavXmlTool::XML_DEFAULT_NAMESPACE, 'locktype')->item(0)->firstChild->localName === 'write' ? ezcWebdavLockRequest::TYPE_WRITE : ezcWebdavLockRequest::TYPE_READ, $domElement->getElementsByTagNameNS(ezcWebdavXmlTool::XML_DEFAULT_NAMESPACE, 'lockscope')->item(0)->firstChild->localName === 'shared' ? ezcWebdavLockRequest::SCOPE_SHARED : ezcWebdavLockRequest::SCOPE_EXCLUSIVE); }
/** * Allow getElementsByTagName to use the defined namespaces. * * @param string $name * @return \DOMNodeList */ public function getElementsByTagName($name) { list($namespace, $localName) = $this->resolveTagName($name); if ($namespace != '') { return parent::getElementsByTagNameNS($namespace, $localName); } else { return parent::getElementsByTagName($localName); } }
/** * Answer an identifier from a CAS entry XML element * * @param DOMElement $element * @return string * @access public * @since 10/6/09 */ public function _getIdFromCASEntry(DOMElement $element) { // Check for a user id. $ids = $element->getElementsByTagNameNS('http://www.yale.edu/tp/cas', 'user'); if ($ids->length) { return $ids->item(0)->nodeValue; } // Check for a group id. $ids = $element->getElementsByTagNameNS('http://www.yale.edu/tp/cas', 'group'); if ($ids->length) { return $ids->item(0)->nodeValue; } throw new OperationFailedException("No cas:user or cas:group available in \n\n" . $element->ownerDocument->saveXML($element)); }
/** * {@inheritDoc} */ protected function parseRoute(RouteCollection $collection, \DOMElement $node, $path) { // the Symfony Routing component uses a path attribute since Symfony 2.2 // instead of the deprecated pattern attribute0 if (!$node->hasAttribute('path')) { $node->setAttribute('path', $node->getAttribute('pattern')); $node->removeAttribute('pattern'); } if ($this->includeFormat) { $path = $node->getAttribute('path'); // append format placeholder if not present if (false === strpos($path, '{_format}')) { $node->setAttribute('path', $path . '.{_format}'); } // set format requirement if configured globally $requirements = $node->getElementsByTagNameNS(self::NAMESPACE_URI, 'requirement'); $format = null; for ($i = 0; $i < $requirements->length; $i++) { $item = $requirements->item($i); if ($item instanceof \DOMElement && $item->hasAttribute('_format')) { $format = $item->getAttribute('_format'); break; } } if (null === $format && !empty($this->formats)) { $requirement = $node->ownerDocument->createElementNs(self::NAMESPACE_URI, 'requirement', implode('|', array_keys($this->formats))); $requirement->setAttribute('key', '_format'); $node->appendChild($requirement); /*$doc =new \DOMDocument(); $doc->appendChild($doc->importNode($node, true)); echo $doc->saveHTML();*/ } } // set the default format if configured if (null !== $this->defaultFormat) { $config['defaults']['_format'] = $this->defaultFormat; $defaultFormatNode = $node->ownerDocument->createElementNS(self::NAMESPACE_URI, 'default', $this->defaultFormat); $defaultFormatNode->setAttribute('key', '_format'); $node->appendChild($defaultFormatNode); } parent::parseRoute($collection, $node, $path); }
/** * Determine output encoding. * * Note: This is a workaround for the problem that when calling: * <code> * $result= $processor->transformToXML($xml); * </code> * the charset of $result (a string) is unknown. * * When using: * <code> * $result= $processor->transformToDoc($xml); * </code> * the charset can be retrieved by having a look at $result's actualEncoding * property, but then again the output method is neglected and we do not * know what to save the result as (saveHTML? saveXML?) * * Thus we manually check for xsl:output in the stylesheet and all its * includes and imports (recursively!) - the overhead is typically about * 8 to 10 milliseconds. * * @param php.DOMElement root * @param string base * @return string encoding or NULL if no user-defined encoding could be found * @throws xml.TransformerException in case an include or import cannot be found */ protected function determineOutputEncoding(\DOMElement $root, $base) { static $xsltNs = 'http://www.w3.org/1999/XSL/Transform'; // Check whether a xsl:output-method tag exists and if it has an // encoding attribute - in this case, we've one. if ($output = $root->getElementsByTagNameNS($xsltNs, 'output')->item(0)) { if ($e = $output->getAttribute('encoding')) { return $e; } } $baseDir = dirname($base); // Check xsl:include nodes foreach ($root->getElementsByTagNameNS($xsltNs, 'include') as $include) { $dom = new \DOMDocument(); $href = $include->getAttribute('href'); if (!('/' === $href[0] || strstr($href, '://') || ':/' === substr($href, 1, 2))) { $href = $baseDir . '/' . $href; // Relative } if (!$dom->load(urldecode($href))) { throw new TransformerException('Cannot find include ' . $href . "\n at " . $base); } if ($e = $this->determineOutputEncoding($dom->documentElement, $href)) { return $e; } } // Check xsl:import nodes foreach ($root->getElementsByTagNameNS($xsltNs, 'import') as $import) { $dom = new \DOMDocument(); $href = $import->getAttribute('href'); if (!('/' === $href[0] || strstr($href, '://') || ':/' === substr($href, 1, 2))) { $href = $baseDir . '/' . $href; // Relative } if (!$dom->load(urldecode($href))) { throw new TransformerException('Cannot find import ' . $href . "\n at " . $base); } if ($e = $this->determineOutputEncoding($dom->documentElement, $href)) { return $e; } } // Cannot determine encoding return null; }
/** * Parses the config elements (default, requirement, option). * * @param \DOMElement $node Element to parse that contains the configs * @param string $path Full path of the XML file being processed * * @return array An array with the defaults as first item, requirements as second and options as third. * * @throws \InvalidArgumentException When the XML is invalid */ private function parseConfigs(\DOMElement $node, $path) { $defaults = array(); $requirements = array(); $options = array(); $locales = array(); foreach ($node->getElementsByTagNameNS(self::NAMESPACE_URI, '*') as $n) { /** @var \DOMElement $n */ switch ($n->localName) { case 'default': if ($n->hasAttribute('xsi:nil') && 'true' == $n->getAttribute('xsi:nil')) { $defaults[$n->getAttribute('key')] = null; } else { $defaults[$n->getAttribute('key')] = trim($n->textContent); } break; case 'requirement': $requirements[$n->getAttribute('key')] = trim($n->textContent); break; case 'option': $options[$n->getAttribute('key')] = trim($n->textContent); break; case 'locale': $locales[$n->getAttribute('key')] = trim((string) $n->nodeValue); break; default: throw new \InvalidArgumentException(sprintf('Unknown tag "%s" used in file "%s". Expected "default", "requirement", "option" or "locale".', $n->localName, $path)); } } return array($defaults, $requirements, $options, $locales); }
/** * @inheritdoc */ public static function fromXml(\DOMElement $element, array $xmlNamespaces = array()) { $locks = array(); foreach ($element->getElementsByTagNameNS('DAV:', 'activelock') as $xActiveLock) { $locks[] = Lock::fromXml($xActiveLock); } return new self($locks); }
public function processAtomFeed(DOMElement $feed, $source) { $entries = $feed->getElementsByTagNameNS(Activity::ATOM, 'entry'); if ($entries->length == 0) { common_log(LOG_ERR, __METHOD__ . ": no entries in feed update, ignoring"); return; } $this->processEntries($entries, $feed, $source); }
/** * Parses the config elements (default, requirement, option). * * @param \DOMElement $node Element to parse that contains the configs * @param string $path Full path of the XML file being processed * * @return array An array with the defaults as first item, requirements as second and options as third. * * @throws \InvalidArgumentException When the XML is invalid */ private function parseConfigs(\DOMElement $node, $path) { $defaults = array(); $requirements = array(); $options = array(); $condition = null; foreach ($node->getElementsByTagNameNS(self::NAMESPACE_URI, '*') as $n) { switch ($n->localName) { case 'default': if ($this->isElementValueNull($n)) { $defaults[$n->getAttribute('key')] = null; } else { $defaults[$n->getAttribute('key')] = trim($n->textContent); } break; case 'requirement': $requirements[$n->getAttribute('key')] = trim($n->textContent); break; case 'option': $options[$n->getAttribute('key')] = trim($n->textContent); break; case 'condition': $condition = trim($n->textContent); break; default: throw new \InvalidArgumentException(sprintf('Unknown tag "%s" used in file "%s". Expected "default", "requirement" or "option".', $n->localName, $path)); } } return array($defaults, $requirements, $options, $condition); }
/** * Extracts the <link /> XML elements. * * This method extracts the <link /> XML elements from the <source /> * element and returns the corresponding {@link * ezcWebdavSourcePropertyLink} object to be used as the content of {@link * ezcWebdavSourceProperty}. * * @param DOMElement $domElement * @return ezcWebdavSourcePropertyLink */ protected function extractLinkContent(DOMElement $domElement) { $links = array(); $linkElements = $domElement->getElementsByTagNameNS(ezcWebdavXmlTool::XML_DEFAULT_NAMESPACE, 'link'); for ($i = 0; $i < $linkElements->length; ++$i) { $links[] = new ezcWebdavSourcePropertyLink($linkElements->item($i)->getElementsByTagNameNS(ezcWebdavXmlTool::XML_DEFAULT_NAMESPACE, 'src')->nodeValue, $linkElements->item($i)->getElementsByTagNameNS(ezcWebdavXmlTool::XML_DEFAULT_NAMESPACE, 'dst')->nodeValue); } return $links; }