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
Parameters
Description
Examples
AttributeValue(xmlTree, attrName)
AttributeValueWithDefault(xmlTree, attrName, defValue)
xmlTree
-
Maple XML tree; XML element
attrName
string; attribute name
defValue
string; default value
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.
with⁡XMLTools:
xmlTree≔XMLElement⁡a,colour=red,some text,XMLElement⁡b,colour=blue,more text
xmlTree≔_XML_Element⁡_XML_ElementType⁡a,_XML_Attribute⁡_XML_AttrName⁡colour,_XML_AttrValue⁡red,_XML_Text⁡some text,_XML_Element⁡_XML_ElementType⁡b,_XML_Attribute⁡_XML_AttrName⁡colour,_XML_AttrValue⁡blue,_XML_Text⁡more text
AttributeValue⁡xmlTree,colour
red
AttributeValue⁡xmlTree,color
Error, (in XMLTools:-AttributeValue) there is no attribute `color' in the given element
AttributeValueWithDefault⁡xmlTree,colour,color
See Also
XMLTools[Attributes]
XMLTools[HasAttributes]
Download Help Document