xmlTreeGetAttributeContent

 

SYNOPSIS

string xmlTreeGetAttributeContent(xmlNode element, string name
                                      [, string ns_URI])

Parameters:

  • element - the element that contains the attribute you want the value of

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

  • ns_URI (optional) - the namespace URI of the attribute you'd like to retrieve (defaults to any namespace)

Returns:

  • the value of the attribute name on the element


DESCRIPTION
xmlTreeGetAttributeContent() gets the content of an attribute on an element, based on the name of the attribute. It is essentially a shortcut for the combination of xmlTreeGetAttributes() to get the attribute name, and then xmlTreeGetContent() to get its content.

If no ns_URI is specified, then the namespace prefix/URIs are disregarded and only local names are compared. If a ns_URI is provided, only an attribute that matches a name and the namespace URI will be returned. This includes the empty namespace; if you pass in a ns_URI as '', then only the attribute matching that name and without a namespace will be returned.


EXAMPLE

<$content = (xmlTreeGetAttributeContent($node, 'myattr'))>


CAVEATS
xmlTreeGetAttributeContent() does not easily give a way to discern between the attribute not being present and the attribute being present, but with no value (i.e. <item attr=''/>).

If you need to be able to discern between the two, use xmlTreeGetAttributes() to first see if the attribute is present, and if so, then use xmlTreeGetContent() on the attribute.

If multiple attributes with the same local name exist with different namespaces and no ns_URI is given, the first one it finds is returned. If you want a specific attribute, provide the proper ns_URI for it (which could be '' for the default namespace).


SEE ALSO
xmlTreeGetName, xmlTreeGetContent, xmlTreeGetAllContent, xmlTreeGetLine, xmlTreeGetType, xmlTreeIsBlankNode


Copyright © Thunderstone Software     Last updated: Sep 25 2019
Copyright © 2019 Thunderstone Software LLC. All rights reserved.