XMLTools - Maple Programming Help

# Online Help

###### All Products    Maple    MapleSim

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

XMLTools

 AddAttribute
 add an attribute to an XML element

 Calling Sequence AddAttribute(xmlTree, attrName, attrValue) AddAttribute(xmlTree, attr)

Parameters

 xmlTree - Maple XML tree; XML element attrName - string; attribute name attrValue - string; attribute value attr - equation of the form attrName = attrValue; attribute specification

Description

 • The AddAttribute(xmlTree, attr) command creates a new XML element from a given one by adding the specified attributes. The AddAttribute(xmlTree, attrName, attrValue) form of the calling sequence is equivalent to the AddAttribute(xmlTree, attr) form.
 • The input tree xmlTree must not already have an attribute with the specified attribute name $\mathrm{attrName}$. The behavior of this function is unspecified if the XML tree xmlTree already has an attribute named attrName.
 • The attribute encoded as attrName = attrValue is added to the attributes of xmlTree, and the new XML tree is returned. The position of the new attribute among any other attributes that may already exist in the tree is unspecified.

Examples

 > $\mathrm{with}\left(\mathrm{XMLTools}\right):$
 > $\mathrm{AddAttribute}\left(\mathrm{XMLElement}\left("a",\left["foo"="2"\right],\mathrm{XMLElement}\left("b",\left[\right],"some text"\right)\right),"colour","red"\right)$
 ${\mathrm{_XML_Element}}{}\left({\mathrm{_XML_ElementType}}{}\left({"a"}\right){,}\left[{\mathrm{_XML_Attribute}}{}\left({\mathrm{_XML_AttrName}}{}\left({"foo"}\right){,}{\mathrm{_XML_AttrValue}}{}\left({"2"}\right)\right){,}{\mathrm{_XML_Attribute}}{}\left({\mathrm{_XML_AttrName}}{}\left({"colour"}\right){,}{\mathrm{_XML_AttrValue}}{}\left({"red"}\right)\right)\right]{,}\left[{\mathrm{_XML_Element}}{}\left({\mathrm{_XML_ElementType}}{}\left({"b"}\right){,}\left[\right]{,}\left[{\mathrm{_XML_Text}}{}\left({"some text"}\right)\right]\right)\right]\right)$ (1)
 > $\mathrm{AddAttribute}\left(\mathrm{XMLElement}\left("a",\left["foo"="2"\right],\mathrm{XMLElement}\left("b",\left[\right],"some text"\right)\right),"colour"="blue"\right)$
 ${\mathrm{_XML_Element}}{}\left({\mathrm{_XML_ElementType}}{}\left({"a"}\right){,}\left[{\mathrm{_XML_Attribute}}{}\left({\mathrm{_XML_AttrName}}{}\left({"foo"}\right){,}{\mathrm{_XML_AttrValue}}{}\left({"2"}\right)\right){,}{\mathrm{_XML_Attribute}}{}\left({\mathrm{_XML_AttrName}}{}\left({"colour"}\right){,}{\mathrm{_XML_AttrValue}}{}\left({"blue"}\right)\right)\right]{,}\left[{\mathrm{_XML_Element}}{}\left({\mathrm{_XML_ElementType}}{}\left({"b"}\right){,}\left[\right]{,}\left[{\mathrm{_XML_Text}}{}\left({"some text"}\right)\right]\right)\right]\right)$ (2)

The next example returns an error since the attribute value is not of type string.

 > $\mathrm{AddAttribute}\left(\mathrm{XMLElement}\left("a",\left["foo"="2"\right],\mathrm{XMLElement}\left("b",\left[\right],"some text"\right)\right),"size"=2\right)$
 > 

 See Also