getAttribute() public method

Returns the attribute for the given name.
public getAttribute ( string $name, string | null | void $namespace = null ) : string | null
$name string Attribute name
$namespace string | null | void An optional namespace for the retrieved attributes
return string | null The attribute value or NULL if attribute not found
示例#1
0
 /**
  * @dataProvider dataProviderForTestGetAttribute
  *
  * @param string $xml
  * @param string|null $namespace
  * @param array $expectedAttributes
  * @return void
  */
 public function testGetAttribute($xml, $namespace, $expectedAttributes)
 {
     $element = new SimpleXMLElement($xml);
     foreach ($expectedAttributes as $name => $expectedValue) {
         $value = $element->getAttribute($name, $namespace);
         $this->assertEquals($expectedValue, $value);
     }
 }
示例#2
0
 /**
  * If the text node has the attribute 'xml:space="preserve"', then preserve whitespace.
  *
  * @param \Box\Spout\Reader\Wrapper\SimpleXMLElement $textNode The text node element (<t>) whitespace may be preserved
  * @return bool Whether whitespace should be preserved
  */
 protected function shouldPreserveWhitespace($textNode)
 {
     $spaceValue = $textNode->getAttribute('space', 'xml');
     return $spaceValue === 'preserve';
 }