add an attribute to an XML element - Maple 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)




Maple XML tree; XML element



string; attribute name



string; attribute value



equation of the form attrName = attrValue; attribute specification



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 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.



AddAttributeXMLElementa,foo=2,XMLElementb,,some text,colour,red

_XML_Element_XML_ElementTypea,_XML_Attribute_XML_AttrNamefoo,_XML_AttrValue2,_XML_Attribute_XML_AttrNamecolour,_XML_AttrValuered,_XML_Element_XML_ElementTypeb,,_XML_Textsome text


AddAttributeXMLElementa,foo=2,XMLElementb,,some text,colour=blue

_XML_Element_XML_ElementTypea,_XML_Attribute_XML_AttrNamefoo,_XML_AttrValue2,_XML_Attribute_XML_AttrNamecolour,_XML_AttrValueblue,_XML_Element_XML_ElementTypeb,,_XML_Textsome text


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

AddAttributeXMLElementa,foo=2,XMLElementb,,some text,size=2

Error, (in XMLTools:-AddAttribute) invalid input: addAttribute2 expects its 2nd argument, attr, to be of type string = string, but received "size" = 2

See Also

XMLTools, XMLTools[RemoveAttribute]

Download Help Document

Was this information helpful?

Please add your Comment (Optional)
E-mail Address (Optional)
What is ? This question helps us to combat spam