Box\Spout\Reader\Wrapper\SimpleXMLElement::getAttribute PHP 메소드

getAttribute() 공개 메소드

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
리턴 string | null The attribute value or NULL if attribute not found
    public function getAttribute($name, $namespace = null)
    {
        $isPrefix = $namespace !== null;
        $attributes = $this->simpleXMLElement->attributes($namespace, $isPrefix);
        $attributeValue = $attributes->{$name};
        return $attributeValue !== null ? (string) $attributeValue : null;
    }

Usage Example

예제 #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);
     }
 }
All Usage Examples Of Box\Spout\Reader\Wrapper\SimpleXMLElement::getAttribute