本文整理汇总了PHP中DOMElement::getAttribute方法的典型用法代码示例。如果您正苦于以下问题:PHP DOMElement::getAttribute方法的具体用法?PHP DOMElement::getAttribute怎么用?PHP DOMElement::getAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DOMElement
的用法示例。
在下文中一共展示了DOMElement::getAttribute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: visit
public function visit(\DOMElement $node, Compiler $context)
{
if ($node->hasAttribute("from-exp")) {
$filename = $node->getAttribute("from-exp");
} elseif ($node->hasAttribute("from")) {
$filename = '"' . $node->getAttribute("from") . '"';
} else {
throw new Exception("The 'from' or 'from-exp' attribute is required");
}
// remove any non-element node
foreach (iterator_to_array($node->childNodes) as $child) {
if (!$child instanceof \DOMElement) {
$child->parentNode->removeChild($child);
}
}
$context->compileChilds($node);
$code = "embed {$filename}";
if ($node->hasAttribute("ignore-missing") && $node->hasAttribute("ignore-missing") !== false) {
$code .= " ignore missing";
}
if ($node->hasAttribute("with")) {
$code .= " with " . $node->getAttribute("with");
}
if ($node->hasAttribute("only") && $node->getAttribute("only") !== "false") {
$code .= " only";
}
$ext = $context->createControlNode($code);
$set = iterator_to_array($node->childNodes);
$n = $node->ownerDocument->createTextNode("\n");
array_unshift($set, $n);
array_unshift($set, $ext);
$set[] = $context->createControlNode("endembed");
DOMHelper::replaceWithSet($node, $set);
}
示例2: parse
public function parse(DOMElement $element)
{
$this->class = $element->getAttribute('class');
if ($element->hasAttribute('args')) {
$this->args[] = $element->getAttribute('args');
}
for ($i = 0; $i < $element->childNodes->length; $i++) {
$childElement = $element->childNodes->item($i);
if ($childElement->parentNode !== $element) {
continue;
}
if ($childElement instanceof DOMComment || $childElement instanceof DOMText) {
continue;
}
switch ($childElement->nodeName) {
case 'args':
$this->parseArgs($childElement);
break;
case 'targets':
case 'sources':
// already handled by Ezer_XmlStepUtil
break;
default:
throw new Ezer_XmlPersistanceElementNotMappedException($childElement->nodeName);
}
}
}
示例3: __construct
/**
* Initialize an EndpointType.
*
* @param DOMElement|NULL $xml The XML element we should load.
* @throws Exception
*/
public function __construct(DOMElement $xml = NULL)
{
if ($xml === NULL) {
return;
}
if (!$xml->hasAttribute('Binding')) {
throw new Exception('Missing Binding on ' . $xml->tagName);
}
$this->Binding = $xml->getAttribute('Binding');
if (!$xml->hasAttribute('Location')) {
throw new Exception('Missing Location on ' . $xml->tagName);
}
$this->Location = $xml->getAttribute('Location');
if ($xml->hasAttribute('ResponseLocation')) {
$this->ResponseLocation = $xml->getAttribute('ResponseLocation');
}
foreach ($xml->attributes as $a) {
if ($a->namespaceURI === NULL) {
continue;
/* Not namespace-qualified -- skip. */
}
$fullName = '{' . $a->namespaceURI . '}' . $a->localName;
$this->attributes[$fullName] = array('qualifiedName' => $a->nodeName, 'namespaceURI' => $a->namespaceURI, 'value' => $a->value);
}
}
示例4: __construct
/**
* Create a PAOS Request element.
*
* @param DOMElement|NULL $xml The XML element we should load.
*/
public function __construct(DOMElement $xml = NULL)
{
if ($xml === NULL) {
return;
}
if (!$xml->hasAttributeNS(SAML2_Const::NS_SOAP, 'mustUnderstand')) {
throw new Exception('Missing soap-env:mustUnderstand attribute in <paos:Request>.');
} elseif ($xml->getAttributeNS(SAML2_Const::NS_SOAP, 'mustUnderstand') !== '1') {
throw new Exception('Invalid value of soap-env:mustUnderstand attribute in <paos:Request>.');
}
if (!$xml->hasAttributeNS(SAML2_Const::NS_SOAP, 'actor')) {
throw new Exception('Missing soap-env:mustUnderstand attribute in <paos:Request>.');
} elseif ($xml->getAttributeNS(SAML2_Const::NS_SOAP, 'actor') !== 'http://schemas.xmlsoap.org/soap/actor/next') {
throw new Exception('Invalid value of soap-env:actor attribute in <paos:Request>.');
}
if (!$xml->hasAttribute('responseConsumerURL')) {
throw new Exception('Missing responseConsumerURL attribute in <paos:Request>.');
}
$this->responseConsumerURL = $xml->getAttribute('responseConsumerURL');
if (!$xml->hasAttribute('service')) {
throw new Exception('Missing service attribute in <paos:Request>.');
}
$this->service = $xml->getAttribute('service');
if ($xml->hasAttribute('messageID')) {
$this->messageID = $xml->getAttribute('messageID');
}
}
示例5: processSuite
private function processSuite(\DOMElement $suiteEl)
{
$suite = new Suite($suiteEl->getAttribute('context'), new \DateTime($suiteEl->getAttribute('date')), $suiteEl->getAttribute('config-path'), [], [], $suiteEl->getAttribute('uuid'));
$informations = [];
foreach ($suiteEl->query('./env/*') as $envEl) {
$name = $envEl->nodeName;
$info = [];
foreach ($envEl->attributes as $iName => $valueAttr) {
$info[$iName] = $valueAttr->nodeValue;
}
$informations[$name] = new Information($name, $info);
}
$resultClasses = [];
foreach ($suiteEl->query('//result') as $resultEl) {
$class = $resultEl->getAttribute('class');
if (!class_exists($class)) {
throw new \RuntimeException(sprintf('XML file defines a non-existing result class "%s" - maybe you are missing an extension?', $class));
}
$resultClasses[$resultEl->getAttribute('key')] = $class;
}
$suite->setEnvInformations($informations);
foreach ($suiteEl->query('./benchmark') as $benchmarkEl) {
$benchmark = $suite->createBenchmark($benchmarkEl->getAttribute('class'));
$this->processBenchmark($benchmark, $benchmarkEl, $resultClasses);
}
return $suite;
}
示例6: getClassWeight
/**
* Get an elements class/id weight. Uses regular expressions to tell if this
* element looks good or bad.
*
* @param DOMElement $e
* @return number (Integer)
*/
public function getClassWeight($e)
{
if (!$this->flagIsActive(self::FLAG_WEIGHT_CLASSES)) {
return 0;
}
$weight = 0;
if (preg_match($this->regexps['negative'], $e->tagName)) {
$weight -= 250;
}
if (preg_match($this->regexps['positive'], $e->tagName)) {
$weight += 250;
}
/* Look for a special ID */
if ($e->hasAttribute('id') && $e->getAttribute('id') != '') {
if (preg_match($this->regexps['negative'], $e->getAttribute('id'))) {
$weight -= 150;
}
if (preg_match($this->regexps['positive'], $e->getAttribute('id'))) {
$weight += 150;
}
}
/* Look for a special classname */
if ($e->hasAttribute('class') && $e->getAttribute('class') != '') {
$classes = explode(" ", $e->getAttribute('class'));
foreach ($classes as $class) {
if (preg_match($this->regexps['negative'], $class)) {
$weight -= 25;
}
if (preg_match($this->regexps['positive'], $class)) {
$weight += 25;
}
}
}
return $weight;
}
示例7: __construct
/**
* Parse given Flickr Image element
*
* @param DOMElement $image
* @return void
*/
public function __construct(DOMElement $image)
{
$this->uri = (string) $image->getAttribute('source');
$this->clickUri = (string) $image->getAttribute('url');
$this->height = (int) $image->getAttribute('height');
$this->width = (int) $image->getAttribute('width');
}
示例8: initFromXmlNode
public function initFromXmlNode(DOMElement $node)
{
$this->selected = $node->getAttribute('selected') == 'true';
$this->text = trim($node->textContent);
if ($node->hasAttribute('customAnswer')) {
$this->customAnswer = trim($node->getAttribute('customAnswer'));
}
}
示例9: getAttribute
/**
* @param string $name
* @return string
* @throws UnexpectedValueException
*/
protected function getAttribute($name)
{
$attribute = $this->element->getAttribute($name);
if ($attribute === '') {
throw new UnexpectedValueException(sprintf('Missing attribute "%s"', $name));
}
return $attribute;
}
示例10: parseElement
/**
* @param \DOMElement $element
* @return int
*/
public function parseElement(\DOMElement $element)
{
if ($element->hasAttribute(CodepointAssignedParser::ATTR_CODEPOINT)) {
return 1;
}
$first = hexdec($element->getAttribute(CodepointAssignedParser::ATTR_CODEPOINT_FIRST));
$last = hexdec($element->getAttribute(CodepointAssignedParser::ATTR_CODEPOINT_LAST));
return $last - $first + 1;
}
示例11: createRefMark
/**
* Creates a ref-mark as the first element of the given $odtElement, based
* on the ID attribute of the given $docbookElement.
*
* @param DOMElement $docbookElement
* @param DOMElement $odtElement
*/
protected function createRefMark(DOMElement $docbookElement, DOMElement $odtElement)
{
// Work around for DocBook inconsistency in using ID or id. id
// would be correct, if one follows the specs here…
if ($docbookElement->hasAttribute('ID') || $docbookElement->hasAttribute('id')) {
$refMark = $odtElement->insertBefore($odtElement->ownerDocument->createElementNS(ezcDocumentOdt::NS_ODT_TEXT, 'text:reference-mark'), $odtElement->firstChild);
$refMark->setAttributeNS(ezcDocumentOdt::NS_ODT_TEXT, 'text:name', $docbookElement->hasAttribute('ID') ? $docbookElement->getAttribute('ID') : $docbookElement->getAttribute('id'));
}
}
示例12: element2Resource
/**
* @param DOMElement $element
* @return Resource
*/
private function element2Resource(DOMElement $element)
{
$resource = new Resource();
$resource->id = $element->getAttribute('id');
$resource->value = $element->getAttribute('value');
foreach ($element->childNodes as $domElement) {
$resource->resources[] = $this->element2Resource($domElement);
}
return $resource;
}
示例13: getPharAliasFromNode
/**
* @param \DOMElement $element
*
* @return PharAlias
*/
private function getPharAliasFromNode(\DOMElement $element)
{
$parser = new VersionConstraintParser();
if ($element->hasAttribute('version')) {
$version = $parser->parse($element->getAttribute('version'));
} else {
$version = new AnyVersionConstraint();
}
return new PharAlias($element->getAttribute('name'), $version);
}
示例14: __construct
public function __construct(DOMElement $node, jackalope_NodeType_NodeTypeManager $nodeTypeManager)
{
$this->nodeTypeManager = $nodeTypeManager;
$this->declaringNodeType = $node->getAttribute('declaringNodeType');
$this->name = $node->getAttribute('name');
$this->isAutoCreated = jackalope_Helper::getBoolAttribute($node, 'isAutoCreated');
$this->isMandatory = jackalope_Helper::getBoolAttribute($node, 'mandatory');
$this->isProtected = jackalope_Helper::getBoolAttribute($node, 'isProtected');
$this->onParentVersion = PHPCR_Version_OnParentVersionAction::valueFromName($node->getAttribute('onParentVersion'));
}
示例15: filterElement
/**
* Filter a single element
*
* @param DOMElement $element
* @return void
*/
public function filterElement(DOMElement $element)
{
if ($element->hasAttribute('rowspan') && $element->getAttribute('rowspan') > 1) {
$attributes = $element->getProperty('attributes');
$attributes['morerows'] = $element->getAttribute('rowspan') - 1;
$element->setProperty('attributes', $attributes);
}
// @todo: Handle colspan, too - even it is quite complex to express in
// docbook.
}