XmlSetAttr Function
Sets an attribute for a node.
Usage
result = XmlSetAttr(node_id, attr_name)
Input Parameters
node_id—Handle returned by XmlEvaluate or XmlNewNode.
attr_name—A string containing the attribute name for this node.
Returned Value
result—The node ID passed in is returned in the result or -1 if an error occurred.
Keywords
attr_value—A string containing the attribute value.
New—Creates a new attribute for the given node. XmlSetAttr function will replace the attributes of a node if the “New” keyword is not used. The New keyword allows you to create multiple attributes with the same name for the same node, which is not typically done but is valid for XML documents.
Remove—If set removes the specified attribute carried by a node.
Discussion
Attributes for nodes are name value pairs associated with a node. For example the following XML node has two attributes; height and width:
<display height=512 width=640></display>
When you parse the XML document containing this node you can change these attributes, remove them, or add new attributes.
Example 1
This example creates an attribute for an XML node. The attribute is “X” and the value for that attribute is [1,3,6,8].
; Create a new node.
xml_node = XmlNewNode('Data')
; Set an attribute for the newly created node.
result = XmlSetAttr(xml_node, 'X', attr_value='[1, 3, 6, 8]')
Example 2
This example creates two new attributes with the same name for a node.
; Create a new node.
xml_node = XmlNewNode('Data')
; Set the 'X' attribute for the newly created node.
result = XmlSetAttr(xml_node, 'X', Attr_value='[1, 3, 6, 8]')
; Create a new attribute also called 'X' but with
; different value.
result = XmlSetAttr(xml_node, 'X', $
         Attr_value='[6, 5, 7, 1]', /New)
Example 3
This example creates then replaces the attribute value for a node.
; Create a new node.
xml_node = XmlNewNode('Data')
; Set the 'X' attribute.
result = XmlSetAttr(xml_node, 'X', Attr_value='[1, 3, 6, 8]')
; Replace the 'X' attribute value.
result = XmlSetAttr(xml_node, 'X', Attr_value='[2, 7, 9, 12]')
Example 4
This example removes an attribute from a node.
; Create a new node.
xml_node = XmlNewNode('Data')
; Set the 'X' attribute.
result = XmlSetAttr(xml_node, 'X', Attr_value='[1, 3, 6, 8]')
; Remove the 'X' attribute.
result = XmlSetAttr(xml_node, 'X', /Remove)