AddAttribute method: XmlNode class

Syntax

AddAttribute(Name, Value);

Description

Use the AddAttribute method to add an attribute to an XmlNode. A reference to the newly created attribute is returned.

If you specify an attribute name that already exists, the new value you use replaces the existing value, and a reference to the attribute is returned.

Attributes added by the AddAttribute method appear in an arbitrary order in the generated XML.

Parameters

Parameter Description

Name

Specify the name of the Attribute that you want to create, as a string.

Value

Specify the value of the Attribute that you want to create, as a string.

Returns

None.

Example

Here is a set of XML response code.

<?xml version="1.0"?> 
<myroot> 
   <postreqresponse> 
      <candidate> 
         <user> 
            <location scenery="great" density="low" blank="eh?"/> 
            
         </user> 
      </candidate> 
   </postreqresponse> 
</myroot>

Here's the PeopleCode that builds it.

Local XmlDoc &inXMLDoc;
Local XmlNode &postReqNode;
Local XmlNode &candidatesNode;
Local XmlNode &userNode;
Local XmlNode &locationNode;
Local XmlNode &sceneryAtt;
Local XmlNode &densityAtt;
Local XmlNode &blankAtt;
Local boolean &ret;

&inXMLDoc = CreateXmlDoc("<?xml version='1.0'?><myroot/>");

&postReqNode = &inXMLDoc.DocumentElement.AddElement("postreqresponse");
&candidatesNode = &postReqNode.AddElement("candidates");
&userNode = &candidatesNode.AddElement("user");
&locationNode = &userNode.AddElement("location");

&locationNode.AddAttribute("scenery", "great");
&locationNode.AddAttribute("density", "low");
&locationNode.AddAttribute("blank", "eh?");