pp108 : setNodeValue()

setNodeValue()


It sets the value for a node (element) in XML. It creates the node if it is not present and sets the value.

Syntax

Script

oNewNode = WebForm.setNodeValue(oNodeReference, sXPath, sValue, bIsComplex)


Parameters

Parameter

Description

oNodeReference

Object that denotes the XML object which needs to be manipulated.

sXPath

String that denotes the path of the node (element) in the oNode object for which the value needs to be set. If the specified node is not available, it will be created.

sValue

String that denotes the value that will be set for the node specified in the sPath

blsComplex

Takes boolean value. The following are the possible values for this property:

  • True: This is the default value. A new node will be created irrespective of whether it is present or not.
  • False : A new node is created only if it is not present.


Return Value


Returns the modified node object.

Remarks


This method is used for easy manipulation of xml nodes. A typical usage of this method would be the manipulation of request messages. If the parameters for the request need to be modified, then this method would be a substitute for the DHTML scripts to be written to search for the node and setting the value. Also if the node is not available, this method will create a node and set its value.

Sample Code

// XML used in the example is as below. This should be placed in the XML Editor.
 <xml id="root">
        <employees>
            <empid/>
        </employees>
 </xml>
 //Example 1
 var request = cordys.cloneXMLDocument(root.XMLDocument);
 WebForm.setNodeValue(cordys.selectXMLNode(request,".//*[local-name()='employees']"), "empid", "2", true);
 //Result (value of 'request' after the method setNodeValue is called)
  <employees>
       <empid/>
       <empid>2</empid>
  <employees>
 //Example 2
 var request = cordys.cloneXMLDocument(root.XMLDocument);
 WebForm.setNodeValue(cordys.selectXMLNode(request,".//*[local-name()='employees']"), "empid", "2", false);
//Result (value of 'request' after the method setNodeValue is called)
  <employees>
      <empid>2</empid>
  </employees>

Applies to


WebForm