You are here: FME Transformers > XML > XMLUpdater

XMLUpdater

This transformer modifies XML documents by performing one or more of the following actions:

For each document update, an XML path expression is used to identify the location of the items to be modified. Note that the path may refer to more than one item. If this is the case, all the items will be modified.

For modifications that replace existing items or insert new items, two parameters are given which specify the value to be added to the document. This value may be given as a simple text value, or it may be an XQuery expression.

The UPDATE features provide the attribute values used in the document update operations. The DOCUMENT feature is only used to supply the XML document which is to be updated.

For each feature that enters the UPDATE port, all update operations listed in the transformer will be applied to each feature that entered the transformer through the DOCUMENT port. Therefore, no changes will be made to the XML document if no features enter the transformer through the UPDATE port.

Note that if the document is entered directly into the transformer parameters, it may be processed in two different ways:

Input Ports

Output Ports

Parameters

XML Document

Updates

The simplest parameter value is a path expression, for example:

/data/record/name

With this path expression, the transformer will modify every <name> element which is contained in a <record> element which is contained in a root <data> element. A predicate may be used to narrow down this selection. For example, to modify the <name> element in the first <record> only, the following path could be used:

/data/record[1]/name

Similarly, a predicate may also be used to narrow the selection based on an attribute value:

/data/record[@id = "A-123"]/name

Notably, since this is an XQuery expression, the FME XQuery functions may be used.

Note that the XQuery functions used in the Path parameter will apply to the UPDATE feature being processed, not the DOCUMENT feature that is being updated

/data/record[@id=fme:get-attribute("record_id")]/name.

The transformer will modify only those <name> elements contained in a <record> element whose id attribute is equal to the record_id feature attribute. This also works with list attributes. The following path expression will modify all <name> elements contained in a <record> element whose id attribute is contained in the _ids feature attribute.

/data/record[@id=fme:get-list-attribute("_ids{}")]/name

The path expression must be namespace correct. That is, the prefixes (or lack of prefixes) must match exactly the prefixes used in the input XML document. A wildcard (*) may be used as a namespace prefix. The path /*:data will match a <data> element in any namespace, including the default namespace and empty namespace. Similarly, a wildcard may be used for an element name. The path gml:* will match any element in the namespace bound to the gml prefix. To combine these approaches, the *:* syntax may not be used. Rather, a single * character should be used.

Update Type

This parameter specifies the type of modification to apply to the XML document. The possible updates are:

Update Type Description

Replace

Each of the items referred to by the XML Path parameter will be replaced with the value given in the New Value parameter.

Replace contents

Each of the items referred to by the XML Path parameter will have their content replaced with the value given in the New Value parameter.

Replace with contents

Each of the items referred to by the XML Path parameter will be replaced with their contents. That is, the node will be removed but the node's children and text content will remain.

Delete

Each of the items referred to by the XML Path parameter will be removed from the document.

Delete contents

The contents of the items referred to by the XML Path parameter will be removed from the document. If the path refers to an element, all child elements and text content of referred elements will be deleted, while attributes will be unmodified. If the path refers to an attribute, its value will be removed.

Rename

The element or attribute referred to by the path will be renamed. Note that if the Type of New Value parameter is XML/XQuery, then the XQuery expression in the New Value parameter should evaluate to a string or a QName object.

Insert as first child

The value given in the New Value parameter will be inserted as the first child of each element referred to by the XML Path parameter.

Insert as last child

The value given in the New Value parameter will be inserted as the last child of each element referred to by the XML Path parameter.

Insert as previous sibling

The value given in the New Value parameter will be inserted into the parent element of each item referred to by the XML Path parameter. It will appear immediately before the referred item.

Insert as next sibling

The value given in the New Value parameter will be inserted into the parent element of each item referred to by the XML Path parameter. It will appear immediately after the referred item.

Result

Editing Transformer Parameters

About Transformer Parameter Options

Transformer Categories

XML

Search FMEpedia

Search for samples and information about this transformer on FMEpedia.