xmlReaderGetAttribute

 

SYNOPSIS

    string xmlReaderGetAttribute(xmlReader reader, string name
    [, string nsURI])

Parameters:

  • xmlReader - the xmlReader object

  • name - the name of the attribute whose value you want

  • nsURI (optional) - The URI or the namespace for the attribute. Defaults to any namespace.

Returns:

  • The value of the attribute.


DESCRIPTION
xmlReaderGetAttribute() gets the value of a specific attribute on the current element.

If no nsURI is given, then the qualified name (ns prefix:local name) is used, and the namespace URI is not considered. If a nsURI is given, then the attribute with that local name in the nsURI namespace will be fetched, regardless of prefix.


EXAMPLE

    <capture>
<?xml version="1.0"?>
<top attr1="attr1 noNS" myns:attr1="attr1 myns"
                        xmlns:myns="urn:nsExample"/>
    </capture><$xml = $ret>
    <$reader = (xmlReaderNewFromString($xml))>

    <!-- move to the first element -->
    <$ret = (xmlReaderRead($reader))>

    <$val1 = (xmlReaderGetAttribute($reader, 'attr1'))>
    no ns, no prefix: ($val1)
    <$val2 = (xmlReaderGetAttribute($reader, 'myns:attr1'))>
    no ns, myns prefix: ($val2)
    <$val3 = (xmlReaderGetAttribute($reader, 'attr1', ''))>
    blank ns: ($val3)
    <$val4 = (xmlReaderGetAttribute($reader, 'attr1',
                                    'urn:nsExample'))>
    nsExample ns: ($val4)

Will produce the following output:

no ns, no prefix: (attr1 noNS)
no ns, myns prefix: (attr1 myns)
blank ns: (attr1 noNS)
nsExample ns: (attr1 myns)


SEE ALSO
xmlReaderGetAttributeCount, xmlReaderGetAttributeNumber


Copyright © Thunderstone Software     Last updated: Dec 10 2018
Copyright © 2019 Thunderstone Software LLC. All rights reserved.