XML - Create node

Declaration

<AMXML ACTIVITY="create_node" XPATH="text" NEWNODE="text" NEWVALUE="text" DEFAULTNSPREFIX="text" DEFAULTNAMESPACE="text"  INSERTAT="text (options)" SPECIFIEDNODE="text" SPECIFIEDNODENOTEXIST="text (options)" SESSION="text"><ATTRIBUTE NAME="text" VALUE="text" /><NAMESPACE PREFIX="text" URI="text" /></AMXML>

Related Topics  

Description

Creates a new node in an existing XML file. Optionally, assigns one or more attribute name value pairs into the new node.

IMPORTANT: The use of Automate Desktop's XML activities requires a fundamental understanding of XML schema and general knowledge of XML-related terms, such as Nodes, XPath, DTD and XSLT.  

Practical usage

Mainly used to create a new node or modify an existing node in an XML document tree.

Parameters

Session

Property Type Required Default Markup Description
Session Text Yes XMLSession1 SESSIONNAME="myXMLSession" The name of an existing XML session in which to associate this activity with. As a safety measure, when a session is created, the XML file bound by that session is saved in memory and the original file is locked. Any modifications by subsequent XML steps are performed on a copy of the XML data saved to memory instead of the original. Linking several activities to a single session eliminates redundancy. Additionally, a single task supports simultaneous execution of multiple sessions, improving overall efficiency. Use the XML - Output file or XML - Save activity to output the in-memory representation of the XML session to a file or variable. To end the session, use the XML - End session activity. 

Node

Property Type Required Default Markup Description
XPath expression Text Yes (Empty) XPATH="/BookStore/book" The XPath expression to the XML node in which to create.
Name Text Yes (Empty) NEWNODE="NodeName" The name of the new node to be created.
Value Text No (Empty) VALUE="theValue" The value of the new node to be created.
If node already exists Text (options) No Ignore
  • NODEWITHSAMENAMEEXISTTHEN="ignore"
  • NODEWITHSAMENAMEEXISTTHEN="skip"
  • NODEWITHSAMENAMEEXISTTHEN="overwrite"
  • NODEWITHSAMENAMEEXISTTHEN="fail"
Specifies what action to perform if a node with same name as the one being inserted at the current location already exists. The available options are:
  • Ignore (default) - Creates a new node regardless of whether a node with the same name exists.
  • Skip - Skips a child node if any child nodes exist with the same name as the new node.
  • Overwrite - Overwrites any child nodes it finds that have the same name as the new node. If multiple child nodes with the same name exist, this activity creates only one of them and erases the rest.
  • Fail - If any child nodes exist with the same name, this activity will fail.

Advanced

Property Type Required Default Markup Description
Default namespace prefix Text No (Empty) DEFAULTNSPREFIX="thePrefix" The prefix associated to the default namespace. A namespace prefix is a text string assigned as an element name prefix to a namespace. When an element name is preceded by the prefix and a colon, then that element is in that assigned namespace.
Default namespace URI Text No (Empty) DEFAULTNAMESPACE="default" The Uniform Resource Identifier (URI) associated to the default namespace. A URI is a string of characters which identifies an Internet Resource.
Insert node at Text (options) No Beginning of child nodes
  • INSERTAT="beginning"
  • INSERTAT="end"
  • INSERTAT="after"
  • INSERTAT="before"
Specifies where to insert the node onto the child nodes. The available options are:
  • Beginning of child nodes (default) - Insert at the beginning of child nodes.
  • End of child nodes - Insert at the end of child nodes.
  • After specified child node - Insert after a specific child node.
  • Before specified child node - Insert before a specific child node.
Specified child node name Text No (Empty) SPECIFIEDNODE="nodeName" The name of the child node in which to insert the node before or after. This parameter is active only if the Insert node at parameter is set to After specified child node or Before specified child node.
If specified child node does not exist Text (options) No Skip
  • SPECIFIEDNODENOTEXIST="skip"
  • SPECIFIEDNODENOTEXIST="fail"
  • SPECIFIEDNODENOTEXIST="insert_beginning"
  • SPECIFIEDNODENOTEXIST="insert_end"
Specifies what action to perform if the specified child node does not exist. This option is active only if the Insert node at parameter is set to After specified child node or Before specified child node. The available options are:
  • Skip (default) - This operation will be skipped.
  • Fail - The step will fail.
  • Insert at beginning of child nodes -  Insert at the beginning of child nodes.
  • Insert at end of child nodes -  Insert at the end of child nodes.
Attribute Name Text No (Empty) Name="AttribName" The name portion of the attribute name-value pair to insert. Use this parameter to insert attributes into the new node. To enter a new row of values select Click here to add new row. To delete an existing row, click the red "X." This parameter supports insertion of multiple attribute name value pairs.
Attribute Value Text No (Empty) Value="AttribValue" The value portion of the attribute name-value pair to insert. Use this parameter to insert attributes into the new node. To enter a new row of values select Click here to add new row. To delete an existing row, click the red "X." This parameter supports insertion of multiple attribute name value pairs.
Namespace Prefix Text No (Empty) PREFIX="PrefixName" The prefix associated to the added namespace. Use this parameter to insert namespace prefix and URI values into the new node. To enter a new row of values select Click here to add new row. To delete an existing row, click the red "X." This parameter supports insertion of multiple namespace prefixes and URIs.
Namespace URI Text No (Empty) URI="URIName" The URI associated to the added namespace. Use this parameter to insert namespace prefix and URI values into the new node. To enter a new row of values select Click here to add new row. To delete an existing row, click the red "X." This parameter supports insertion of multiple namespace prefixes and URIs.

Description

Error Causes

On Error

Example

NOTE:
  • Copy and paste the sample AML code below directly into the Task Builder Steps Panel.
  • To successfully run the sample code, update parameters containing user credentials, files, file paths, or other information specific to the task to match your environment.

Description

This sample task creates XML node Euro with a value of 10 at XPath location /bookstore/book/price.  

Copy
<AMXML ACTIVITY="create_node" XPATH="/bookstore/book/price" NEWNODE="Euro" NEWVALUE="10" SESSION="XmlSession1" />