XMLUpdater
This transformer modifies XML documents by performing one or more of the following actions:
- Replace an XML element or attribute.
- Replace the contents of an element or attribute.
- Delete an XML element or attribute.
- Delete the contents of an XML element or attribute.
- Rename an element or attribute
- Insert a new element or attribute.
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:
- If no Document features are given to the transformer, a new feature will be created to store the document. Each of the updates will be applied to the document, and it will then be output through the Document port.
- If Document features are given to the transformer, each of the updates will be applied to the document, then it will be copied to each Document input feature before these features are output from the transformer.
Input Ports
Input features contain the XML documents to be modified. The documents can be contained in an attribute, entered directly into the transformer, or contained in a file referenced by an attribute value.
For each feature which enters this input port, each of the updates listed in the transformer will be executed on each document which entered via the Document input port. These features will contain the attributes values that are used in the document updates.
Output Ports
The Document input features will be output through this port. These features will contain the updated document, which will be stored in the attribute named in the Result Attribute parameter. The updated document will always be saved as a utf-8 encoded attribute value, regardless of the encoding of the original document.
Parameters
This parameter is used to specify which update features will modify a document. When this parameter is set to a list of attributes, Document features will only be modified by Update features that share the same values for these attributes. The document will be modified by all of the update features with the same attribute values. Note that a document will not be updated if no Update features with the same values for the “group by” attributes are provided to the transformer.
Process At End (Blocking): This is the default behavior. Processing will only occur in this transformer once all input is present.
Process When Group Changes (Advanced): This transformer will process input groups in order. Changes of the value of the Group By parameter on the input stream will trigger processing on the currently accumulating group. This may improve overall speed (particularly with multiple, equally-sized groups), but could cause undesired behavior if input groups are not truly ordered.
There are two typical reasons for using Process When Group Changes (Advanced) . The first is incoming data that is intended to be processed in groups (and is already so ordered). In this case, the structure dictates Group By usage - not performance considerations.
The second possible reason is potential performance gains.
Performance gains are most likely when the data is already sorted (or read using a SQL ORDER BY statement) since less work is required of FME. If the data needs ordering, it can be sorted in the workspace (though the added processing overhead may negate any gains).
Sorting becomes more difficult according to the number of data streams. Multiple streams of data could be almost impossible to sort into the correct order, since all features matching a Group By value need to arrive before any features (of any feature type or dataset) belonging to the next group. In this case, using Group By with Process At End (Blocking) may be the equivalent and simpler approach.
Note: Multiple feature types and features from multiple datasets will not generally naturally occur in the correct order.
As with many scenarios, testing different approaches in your workspace with your data is the only definitive way to identify performance gains.
XML Document
This parameter is used to specify the type of XML document which is to be modified. The XML may come from the input features (Parameter Value: Text or Attribute), or it may come from an external file. (Parameter Value: XML File)
When the XML Input parameter is set to Text or Attribute, this parameter is used to specify the XML file. The parameter may be set to an attribute value, or the XML document may be entered into the parameter directly.
When the XML Input parameter is set to XML File, this parameter is used to specify the location of the file. The file path may be entered directly into the parameter, or the path may come from an attribute value.
Updates
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 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 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 Value Type parameter is XML/XQuery, then the XQuery expression in the Value parameter should evaluate to a string or a QName object. |
Insert as first child |
The value given in the 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 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 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 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. |
This parameter specifies the location of the XML nodes which are to be updated. Any XQuery expression may be used here, as long as it returns nodes contained in the input document. If the path expression evaluates to more than one item, they will all be modified.
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: 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.
This parameter is used to indicate how the value of the Value parameter should be interpreted. The effects of the different values of this parameter are explained in the description of the Value parameter. In general, this parameter should be set to Plain Text if the transformer is intended to insert text content into the document, while it should be set to XML/XQuery if the transformer is intended to insert XML elements into the document.
This parameter is used to specify the new values that should be inserted into the document. If the Value Type parameter is set to Plain Text, the contents of this parameter will be encoded for safe use in an XML document. That is, < characters will be encoded as <, > characters will be encoded as > and so on.
If the Value Type parameter is set to XML/XQuery, the contents of this parameter will be interpreted as an XQuery expression. This allows the insertion of XML elements into the document. Also, this allows the use of the FME XQuery functions. For example, an XML Template (for example, from the XMLTemplater transformer) could be entered as the parameter value. It would then be evaluated before being inserted into the document.
Note: Any FME XQuery functions used in the new value will access the Update feature, not the Document feature.
Parameters
This parameter specifies whether or not Workbench should try to validate the attribute names which are passed to any XQuery functions used in the XML Path column and the Value column.
This parameter specifies the attribute to which the updated XML document will be written. The default is _result.
This parameter specifies whether the updated XML document should start with an XML header declaration. By default, the output will contain an XML header. Omitting the header can be useful when the output is to be concatenated with other values into a larger XML document.
Editing Transformer Parameters
Using a set of menu options, transformer parameters can be assigned by referencing other elements in the workspace. More advanced functions, such as an advanced editor and an arithmetic editor, are also available in some transformers. To access a menu of these options, click beside the applicable parameter. For more information, see Transformer Parameter Menu Options.
Transformer Categories
FME Licensing Level
FME Professional edition and above
Search FME Community
Search for samples and information about this transformer on the FME Community.