PHP
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

DOMElement->getAttributeNode()> <DOMElement->__construct()
Last updated: Sat, 24 Mar 2007

view this page in

DOMElement->getAttribute()

(No version information available, might be only in CVS)

DOMElement->getAttribute() — Returns value of attribute

Popis

class DOMElement {
string getAttribute ( string $name )
}

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

Seznam parametrů

name

The name of the attribute.

Návratové hodnoty

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

Viz také

DOMElement->hasAttribute()
DOMElement->setAttribute()
DOMElement->removeAttribute()



add a note add a note User Contributed Notes
DOMElement->getAttribute()
mpalmer at cybersource dot com
09-Nov-2007 03:32
- - - - - - - - - - - - - -

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 Code:
$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

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

DOMElement->getAttributeNode()> <DOMElement->__construct()
Last updated: Sat, 24 Mar 2007
 
 
show source | credits | stats | sitemap | contact | advertising | mirror sites