XMLTools
AddAttribute
add an attribute to an XML element
Calling Sequence
Parameters
Description
Examples
AddAttribute(xmlTree, attrName, attrValue)
AddAttribute(xmlTree, attr)
xmlTree
-
Maple XML tree; XML element
attrName
string; attribute name
attrValue
string; attribute value
attr
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.
with⁡XMLTools:
AddAttribute⁡XMLElement⁡a,foo=2,XMLElement⁡b,,some text,colour,red
_XML_Element⁡_XML_ElementType⁡a,_XML_Attribute⁡_XML_AttrName⁡foo,_XML_AttrValue⁡2,_XML_Attribute⁡_XML_AttrName⁡colour,_XML_AttrValue⁡red,_XML_Element⁡_XML_ElementType⁡b,,_XML_Text⁡some text
AddAttribute⁡XMLElement⁡a,foo=2,XMLElement⁡b,,some text,colour=blue
_XML_Element⁡_XML_ElementType⁡a,_XML_Attribute⁡_XML_AttrName⁡foo,_XML_AttrValue⁡2,_XML_Attribute⁡_XML_AttrName⁡colour,_XML_AttrValue⁡blue,_XML_Element⁡_XML_ElementType⁡b,,_XML_Text⁡some text
The next example returns an error since the attribute value is not of type string.
AddAttribute⁡XMLElement⁡a,foo=2,XMLElement⁡b,,some text,size=2
Error, (in XMLTools:-AddAttribute) invalid input: XMLTools:-NSXML:-addAttribute2 expects its 2nd argument, attr, to be of type string = string, but received "size" = 2
See Also
XMLTools[RemoveAttribute]
Download Help Document