XML - Create Node

Declaration  

<AMXMLCREATENODE XPATH="text" NEWNODE="text" NEWVALUE="text" NODEWITHSAMENAMEEXISTTHEN="test (options)" DEFAULTNAMESPACE="text" DEFAULTNSPREFIX="text" INSERTAT="text (options)"><Attribute Name="text" Value="text" /></AMXMLCREATENODE>

See Also

XML - Create Session | XML - Dataset to XML | XML - Delete Node | XML - Edit Node | XML - End Session | XML - Evaluate Xpath | XML - Export | XML - Import | XML - Node to Dataset | XML - Read Node | XML - Save | XML - Sign | XML - Transform | XML - Validate | XML - Verify

Create XML Node

Declaration  

<AMXMLCREATENODE XPATH="text" NEWNODE="text" NEWVALUE="text" NODEWITHSAMENAMEEXISTTHEN="test (options)" DEFAULTNAMESPACE="text" DEFAULTNSPREFIX="text" INSERTAT="text (options)"><Attribute Name="text" Value="text" /></AMXMLCREATENODE>

See Also

Create XML Node | Dataset to XML | Delete XML Node | Edit XML Node | End XML Session | Evaluate Xpath Expression | Extract XML Fragment | Merge XML Files | Output XML | Read XML Node | Sign XML Document | Start XML Session | Transform XML | Validate XML File | Verify XML Document | XML Node to Dataset

Description

Creates a new node in an existing XML file. Optionally assigns a value and attribute to the node.

NOTE: When creating an XML task, it is required that an XML session name is initially generated using the Start XML Session action. XML - Create Session activity. This session can be identified by subsequent XML steps that include the same session name, allowing several XML documents to be active within the same task. When an XML session is created, the XML file bound by that session becomes locked. An End XML Session action XML - End Session activity can be used to end the current session and unlock the XML file bound to that session.

During an XML session, modifications are not performed on the original XML file bound by that session. Rather, as a safety measure, a copy of the file is saved to memory upon the creation of a session. Any modifications performed by subsequent XML steps are performed on the copy of the XML data saved to memory. Use the Output XML File action XML - Save activity to output the in-memory representation of the XML session to a file or variable. Using this step does not end the session, thus allowing subsequent XML steps to continue using the session. To end a session, use the  

 

IMPORTANT: AutoMate's XML actions require a basic understanding of XML and related terms, such as XPath, DTD and XSLT.

Practical Usage

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

Parameters

General Properties

Property

Type

Req'd

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=

"Skip"

Specifies what to do if a node with same name as the one being inserted at the current location already exists. The available options are:

  • Ignore (default): Directs the action to create a new node regardless of whether other nodes with the same name exist. Ignore is the Default

  • Skip: Directs the action to skip a child node if any child nodes exist with the same name as the new node.

  • Overwrite: Directs the action to overwrite any child nodes it finds that have the same name as the new node. If multiple child nodes with the same name exist, the action creates only one of them and erases the rest.

  • Fail: Tells the action that if any child nodes exist with the same name, the action will fail.

Insert as first child node

Yes/No

No

No

INSERTASFIRSTCHILD="YES"

If set to YES, allows you to insert the new node as a first child of the parent node found using Xpath Expression. The default value is set to NO..

Session Name

Text

No

XMLSession1

SESSIONNAME=

"FirstXMLSession"

The session name to identify the in-memory XML document to use in subsequent XML steps. This allows several in-memory XML documents to be active simultaneously.

Advanced Properties

Property

Type

Req'd

Default

Markup

Description

Default namespace (optional)

Text

No

(Empty)

DEFAULTNAMESPACE="default"

The default namespace. This parameter is optional.

Prefix for default namespace (optional)

Text

No

(Empty)

DEFAULTNSPREFIX="thePrefix"

The prefix associated to the default namespace.

Insert node at

Text (options)

No

Beginning of child nodes

INSERTAT="after"

Specifies where to insert the node onto the child node. Other parameters may become active depending on which option is selected. The available options are:

  • Beginning of child nodes (default)

  • End of child nodes

  • After specified child node

  • Before specified child node

Specified child node name

Text

No

(Empty)

SPECIFIEDNODE="nodeName"

The name of the child node. This option is active only if the Insert node at parameter is set to After specifies child node or Before specified child node.

If specifies child node does not exist

Text (options)

No

Skip

SPECIFIEDNODENOTEXIST=

"fail"

Specifies what to do if the specified child node does not exist. This option is active only if the Insert node at parameter is set to After specifies child node or Before specified child node. The available options are:

  • Skip

  • Fail

  • Insert at beginning of child nodes

  • Insert at end of child nodes

Attributes Properties

Use these properties to insert attributes into the new node.

Property

Type

Req'd

Default

Markup

Description

Attribute Name

Text

No

(Empty)

Name="AttribName"

The name of the attribute to insert. Once you have specified an attribute name/value, use the following buttons if needed:

  • Move Up - Move the attribute up one line.

  • Move Down - Move the attribute down one line.

  • Add - Once you have given the Attribute Name and Value, click this button to add them to list.

  • Remove - Use this to remove existing attribute names/values.

Attribute Value

Text

No

(Empty)

Value="AttribValue"

The value of the attribute. Once you have specified an attribute name/value, use the following buttons if needed:

  • Move Up - Move the attribute up one line.

  • Move Down - Move the attribute down one line.

  • Add - Once you have given the Attribute Name and Value, click this button to add them to list.

  • Remove - Use this to remove existing attribute names/values.

Namespace Properties

Use these properties to insert namespace prefix and URI into the new node.

Property

Type

Req'd

Default

Markup

Description

Prefix

Text

No

(Empty)

PREFIX="PrefixName"

The prefix associated to the added namespace. Once you have specified namespace properties, use the following buttons if needed:

  • Move Up - Move the namespace up one line.

  • Move Down - Move the namespace down one line.

  • Add - Add the namespace to the list.

  • Remove - Remove existing namespce from the list.

Namespace URI

Text

No

(Empty)

URI="URIName"

The URI associated to the added namespace. Once you have specified namespace properties, use the following buttons if needed:

  • Move Up - Move the namespace up one line.

  • Move Down - Move the namespace down one line.

  • Add - Add the namespace to the list.

  • Remove - Remove existing namespce from the list.

Description Properties

The Description tab allows you to customize the text description of any step as it appears in the Task Builder's Steps Pane.

More on setting custom step description

Error Causes Properties

The Error Causes tab properties lets you instruct a task step to react only to specific errors or ignore certain errors that should cause it to fail.

More on Error Causes properties

On Error Properties

The On Error tab properties lets you determine what the task should do if a particular step encounters an error as defined in the Error Causes properties.

More about On Error properties

Additional Notes

Expressions, Variables & Functions

A percent sign is used as a special character in AutoMate to indicate the beginning and end of an expression. This allows variables, functions and other expressions to be entered in any text parameter of a task's properties. For example: %1+1% inside a task will resolve to 2 at runtime. A more elaborate example is %FileDateTime(myFile)% which results to the date/time of myFile. To help construct expressions, you can open Expression Builder by clicking the Insert Expression (%) button or by pressing F2.

More on expressions

More on variables

More on functions

More on extended functions
More on the expression builder

Example

NOTE: The code below can be copied and pasted directly into the Steps pane of the Task Builder.

 

Description: This sample step creates a node with name "Euro" and value "10" at XPath location "/bookstore/book/price". Session name is "XMLSession1". If a node with the same name already exists as a child, add the node anyway.

<AMXMLCREATENODE XPATH="/bookstore/book/price" NEWNODE="Euro" NEWVALUE="10" INSERTASFIRSTCHILD="YES" />

↑ Top of Page