# XML Typehandler plugin reference

**URL:** <https://community.novulo.com/t/xml-typehandler-plugin-reference/801>\
**Category:** Wiki\
**Tags:** plugin\
**Created:** [August 21, 2025, 6:46am UTC](https://community.novulo.com/t/xml-typehandler-plugin-reference/801 "2025-08-21T06:46:13Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mihai](https://avatars.discourse-cdn.com/v4/letter/m/35a633/32.png) [@Mihai](https://community.novulo.com/u/Mihai)\
**Post date:** [August 21, 2025, 6:46am UTC](https://community.novulo.com/t/xml-typehandler-plugin-reference/801/1 "2025-08-21T06:46:13Z")

</div>

# XML Typehandler Functions Reference

A complete guide to all built-in functions for manipulating XML documents in the XML Typehandler plug-in.

Contents

- [GetOrCreateNodeAction](#GetOrCreateNodeAction)
- [InsertXmlAfterAction](#InsertXmlAfterAction)
- [LoadAction](#LoadAction)
- [RemoveNodeAction](#RemoveNodeAction)
- [ReplaceInnerTextAction](#ReplaceInnerTextAction)
- [SelectNodesAction](#SelectNodesAction)
- [SelectSingleNodeAction](#SelectSingleNodeAction)
- [WriteAction](#WriteAction)

### GetOrCreateNodeAction

Description

Adds the provided attributes under a specified node. If the node does not exist, it is created based on the given configuration.

Behavior

- Locates the parent node based on `parentxpath`. If none is provided, an exception is thrown.
- Finds or creates the child node by combining `nodename + nodematch`.
- If no matching child is found, `nodename` is appended to the parent.
- Attributes are applied. If overwrite = false and attribute exists, nothing changes. Otherwise values are updated or new attributes added.

Example

Input XML:

```auto
<catalog>
  <book id="bk101" />
</catalog>

```

Params:

```auto
parentxpath = "catalog"
nodename = "book"
nodematch = "@id='bk101'"
attrs = [[<"name","category">,<"value","tech">,<"overwrite",false>],
         [<"name","id">,<"value","bk202">,<"overwrite",false>]]

```

Result:

```auto
<catalog>
  <book id="bk101" category="tech" />
</catalog>

```

Parameters

**xml:** XmlDocument (required)  
**parentxpath:** string (optional)  
**nodename:** string (required)  
**nodematch:** string (optional)  
**attrs:** list of 3-tuples (name: string, value: mixed, overwrite: bool) (optional)

### InsertXmlAfterAction

Description

Inserts a given XML fragment after a node identified by an XPath expression.

Behavior

Checks XPath. Inserts fragment after each matched node. Errors if node type disallows insertion.

Example

Input:

```auto
<catalog>
  <book id="bk101" />
  <book id="bk102" />
</catalog>

```

Params:

```auto
node_to_insert_after = "/catalog/book[@id='bk101']"
xml_to_insert = <book id="bk201" />

```

Result:

```auto
<catalog>
  <book id="bk101" />
  <book id="bk201" />
  <book id="bk102" />
</catalog>

```

Parameters

**xml:** XmlDocument (required)  
**node\_to\_insert\_after:** string (required)  
**xml\_to\_insert:** XmlDocument (required)  
**error\_on\_no\_match:** bool (optional, default false)

### LoadAction

Description

Parses an XML document from either a file path, uploaded file, or raw XML string.

Example

Input:

```auto
xmlstring = "<catalog><book id='bk101'/></catalog>"

```

Result:

```auto
success = true
xml = parsed document with root <catalog>

```

Parameters

**xmlfile:** mixed (optional) — file path or uploaded file  
**xmlstring:** string (optional)

### RemoveNodeAction

Description

Removes all XML nodes matching the provided XPath.

Example

Input:

```auto
<catalog>
  <book id="bk101" />
  <book id="bk102" />
</catalog>

```

Param:

```auto
node_to_remove = "/catalog/book[@id='bk102']"

```

Result:

```auto
<catalog>
  <book id="bk101" />
</catalog>

```

Parameters

**xml:** XmlDocument (required)  
**node\_to\_remove:** string (required)  
**error\_on\_no\_match:** bool (optional)

### ReplaceInnerTextAction

Description

Replaces the inner text of XML nodes matched by XPath expressions.

Example

Input:

```auto
<catalog><book id="bk101">Old Title</book></catalog>

```

Param:

```auto
replace = [["/catalog/book[@id='bk101']", "New Title"]]

```

Result:

```auto
<catalog><book id="bk101">New Title</book></catalog>

```

Parameters

**xml:** XmlDocument (required)  
**replace:** list of tuples (xpath, value) (required)  
**error\_on\_no\_match:** bool (optional, default false)

### SelectNodesAction

Description

Evaluates an XPath expression against an XML document and returns all matches.

Example

Input:

```auto
<catalog>
  <book id="bk101">Title 1</book>
  <book id="bk102">Title 2</book>
</catalog>

```

Param:

```auto
xpath = "/catalog/book/@id"

```

Result:

```auto
{"success": true, "matches": ["bk101","bk102"]}

```

Parameters

**xml:** XmlDocument (required)  
**xpath:** string (required)  
**error\_on\_no\_match:** bool (optional)

### SelectSingleNodeAction

Description

Evaluates an XPath expression and returns the first matching node.

Example

Input:

```auto
<catalog>
  <book id="bk101">Title 1</book>
  <book id="bk102">Title 2</book>
</catalog>

```

Param:

```auto
xpath = "/catalog/book[@id='bk101']"

```

Result:

```auto
{"success": true, "match": "Title 1"}

```

Parameters

**xml:** XmlDocument (required)  
**xpath:** string (required)  
**error\_on\_no\_match:** bool (optional)

### WriteAction

Description

Serializes the provided XML document to text using encoding/indent and writes it to DB, file path, or string.

Example

Input:

```auto
<catalog><book id="bk101">Title 1</book></catalog>

```

Param:

```auto
write_to_string = true

```

Result:

```auto
{"success": true, "string": "<catalog>\r\n <book id=\"bk101\">Title 1</book>\r\n</catalog>"}

```

Parameters

**xml:** XmlDocument (required)  
**write\_to\_db:** string (filename) (optional)  
**write\_to\_path:** string (absolute path) (optional)  
**write\_to\_string:** bool (optional, default false)  
**encoding:** string (optional, default “utf-8”)  
**indent:** bool (optional, default true)
