XMLTools - Maple Programming Help

Home : Support : Online Help : Connectivity : Web Features : XMLTools : XMLTools/AttributeValue

XMLTools

 AttributeValue
 retrieve the value of an attribute of an XML element
 AttributeValueWithDefault
 retrieve the value of an attribute of an XML element, or a specified default value if the attribute is not present

 Calling Sequence AttributeValue(xmlTree, attrName) AttributeValueWithDefault(xmlTree, attrName, defValue)

Parameters

 xmlTree - Maple XML tree; XML element attrName - string; attribute name defValue - string; default value

Description

 • The AttributeValue(xmlTree, attrName) command extracts the value of an attribute from the XML element xmlTree. The attribute, whose value is sought, must be specified by its name attrName.
 If the attribute attrName is not present in the XML element xmlTree, an error is returned.
 Note: Only the attributes that belong to the XML element xmlTree are examined. This function does not examine attributes of any subelements.
 • The AttributeValueWithDefault(xmlTree, attrName, defValue) command is similar to AttributeValue, except that it takes a third argument defValue. The defValue parameter is a string that specifies a default value for the named attribute attrName if it is not present in the element represented by xmlTree.
 Note: Only the attributes that belong to the XML element xmlTree are examined. As in the case of AttributeValue, this function does not examine attributes of any subelements.

Examples

 > $\mathrm{with}\left(\mathrm{XMLTools}\right):$
 > $\mathrm{xmlTree}≔\mathrm{XMLElement}\left("a",\left["colour"="red"\right],"some text",\mathrm{XMLElement}\left("b",\left["colour"="blue"\right],"more text"\right)\right)$
 ${\mathrm{xmlTree}}{:=}{\mathrm{_XML_Element}}{}\left({\mathrm{_XML_ElementType}}{}\left({"a"}\right){,}\left[{\mathrm{_XML_Attribute}}{}\left({\mathrm{_XML_AttrName}}{}\left({"colour"}\right){,}{\mathrm{_XML_AttrValue}}{}\left({"red"}\right)\right)\right]{,}\left[{\mathrm{_XML_Text}}{}\left({"some text"}\right){,}{\mathrm{_XML_Element}}{}\left({\mathrm{_XML_ElementType}}{}\left({"b"}\right){,}\left[{\mathrm{_XML_Attribute}}{}\left({\mathrm{_XML_AttrName}}{}\left({"colour"}\right){,}{\mathrm{_XML_AttrValue}}{}\left({"blue"}\right)\right)\right]{,}\left[{\mathrm{_XML_Text}}{}\left({"more text"}\right)\right]\right)\right]\right)$ (1)
 > $\mathrm{AttributeValue}\left(\mathrm{xmlTree},"colour"\right)$
 ${"red"}$ (2)
 > $\mathrm{AttributeValue}\left(\mathrm{xmlTree},"color"\right)$
 > $\mathrm{AttributeValueWithDefault}\left(\mathrm{xmlTree},"colour","color"\right)$
 ${"red"}$ (3)