DOMElement::getAttribute

(PHP 5, PHP 7, PHP 8)

DOMElement::getAttributeReturns value of attribute

Description

public DOMElement::getAttribute(string $qualifiedName): string

Gets the value of the attribute with name qualifiedName for the current node.

Parameters

qualifiedName

The name of the attribute.

Return Values

The value of the attribute, or an empty string if no attribute with the given qualifiedName is found.

See Also

add a note

User Contributed Notes 1 note

up
8
mpalmer at cybersource dot com
17 years ago
- - - - - - - - - - - - - -

XML Data:
<data>
<Report ID="1">
<Date>REVIEW</Date>
<AuthorID>1</AuthorID>
</Report>
<Report ID="2">
<Date>REVIEW</Date>
<AuthorID>2</AuthorID>
</Report>
</data>

- - - - - - - - - - - - - -

<?php
$xmlDoc
= new DOMDocument();
$xmlDoc->load( 'data.xml' );

$searchNode = $xmlDoc->getElementsByTagName( "Report" );

foreach(
$searchNode as $searchNode )
{
$valueID = $searchNode->getAttribute('ID');

$xmlDate = $searchNode->getElementsByTagName( "Date" );
$valueDate = $xmlDate->item(0)->nodeValue;

$xmlAuthorID = $searchNode->getElementsByTagName( "AuthorID" );
$valueAuthorID = $xmlAuthorID->item(0)->nodeValue;

echo
"$valueID - $valueDate - $valueAuthorID\n";
}
?>

- - - - - - - - - - - - - -

Output:

1 - REVIEW - 1
2 - REVIEW - 2

- - - - - - - - - - - - - -
To Top

Follow Lee on X/Twitter - Father, Husband, Serial builder creating AI, crypto, games & web tools. We are friends :) AI Will Come To Life!

Check out: eBank.nz (Art Generator) | Netwrck.com (AI Tools) | Text-Generator.io (AI API) | BitBank.nz (Crypto AI) | ReadingTime (Kids Reading) | RewordGame | BigMultiplayerChess | WebFiddle | How.nz | Helix AI Assistant