XMLReader::getAttribute

(PHP 5 >= 5.1.0, PHP 7, PHP 8)

XMLReader::getAttribute — ćć‰ă‚’ă‚‚ăšă«ă€ć±žæ€§ăźć€€ă‚’ć–ćŸ—ă™ă‚‹

èȘŹæ˜Ž

public function XMLReader::getAttribute(string $name): ?string

æŒ‡ćźšă—ăŸćć‰ăźć±žæ€§ăźć€€ă‚’èż”ă—ăŸă™ă€‚ć±žæ€§ăŒć­˜ćœšă—ăȘかったり çŸćœšäœçœźăŒèŠçŽ ăƒŽăƒŒăƒ‰ă§ăȘă‹ăŁăŸă‚Šă—ăŸć Žćˆă«ăŻ null ă‚’èż”ă—ăŸă™ă€‚

ăƒ‘ăƒ©ăƒĄăƒŒă‚ż

name

ć±žæ€§ăźćć‰ă€‚

æˆ»ă‚Šć€€

ć±žæ€§ăźć€€ă‚’èż”ă—ăŸă™ă€‚æŒ‡ćźšă—ăŸćć‰ name た ć±žæ€§ăŒèŠ‹ă€ă‹ă‚‰ăȘă‹ăŁăŸă‚Šă€çŸćœšäœçœźăŒèŠçŽ ăƒŽăƒŒăƒ‰ă§ăŻăȘă‹ăŁăŸă‚Šă—ăŸć Žćˆă«ăŻ null ă‚’èż”ă—ăŸă™ă€‚

ć€‰æ›Žć±„æ­Ž

ăƒăƒŒă‚žăƒ§ăƒł èȘŹæ˜Ž
8.0.0 ă“ăźé–ąæ•°ăŻ false ă‚’èż”ă•ăȘくăȘă‚ŠăŸă—ăŸă€‚

ć‚è€ƒ

  • XMLReader::getAttributeNo() - ă‚€ăƒłăƒ‡ăƒƒă‚Żă‚čă‚’ă‚‚ăšă«ă€ć±žæ€§ăźć€€ă‚’ć–ćŸ—ă™ă‚‹
  • XMLReader::getAttributeNs() - 損才および URI ă‚’ă‚‚ăšă«ă€ć±žæ€§ăźć€€ă‚’ć–ćŸ—ă™ă‚‹
add a note

User Contributed Notes 3 notes

up
8
Anonymous ¶
15 years ago
Or use XMLReader::ELEMENT and XMLReader::END_ELEMENT rather than the numbers 1 and 15.
up
2
Gabi ¶
18 years ago
might be obvious, but not to everyone ;-) ... when reading attributes from a node that has sub-nodes (and creating an output from this node), the output will be issued twice, once on the <ELEMENT> tag and once on the end tag </ELEMENT>. To avoid this, you can test on which part of the node you are using the property nodeType. 
It'll be 1 for the element, 15 for the end element.
up
0
sven at e7o dot de ¶
2 years ago
To get all attributes and their names, use something like this:

<?php
function getAttributes($reader)
{
    $attributes = [];
    for ($i = 0; $i < $reader->attributeCount; $i++) {
        $reader->moveToAttributeNo($i);
        $attributes[$reader->name] = $reader->value;
    }
    return $attributes;
}
?>