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.
Configuration
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
Group Update Features By |
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. |
Complete Groups |
When All Features Received: This is the default behavior. Processing will only occur in this transformer once all input is present. 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. Considerations for Using Group By
There are two typical reasons for using 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 When All Features Received 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 Input |
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) |
XML Text |
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. |
XML File |
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. |
Update Type |
This parameter specifies the type of modification to apply to the XML document. The possible updates are:
|
||||||||||||||||||||||
XML Path |
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 feature-level XQuery functions (such as fme:get-attribute) 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. |
||||||||||||||||||||||
Value Type |
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. |
||||||||||||||||||||||
Value |
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. |
Validate Attribute Names |
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. |
Write XML Header |
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. |
Updated XML |
Name the attribute to which the updated XML document will be written. The default is _result. |
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.
Defining Values
There are several ways to define a value for use in a Transformer. The simplest is to simply type in a value or string, which can include functions of various types such as attribute references, math and string functions, and workspace parameters. There are a number of tools and shortcuts that can assist in constructing values, generally available from the drop-down context menu adjacent to the value field.
Using the Text Editor
The Text Editor provides a convenient way to construct text strings (including regular expressions) from various data sources, such as attributes, parameters, and constants, where the result is used directly inside a parameter.
Using the Arithmetic Editor
The Arithmetic Editor provides a convenient way to construct math expressions from various data sources, such as attributes, parameters, and feature functions, where the result is used directly inside a parameter.
Conditional Values
Set values depending on one or more test conditions that either pass or fail.
Parameter Condition Definition Dialog
Content
Expressions and strings can include a number of functions, characters, parameters, and more.
When setting values - whether entered directly in a parameter or constructed using one of the editors - strings and expressions containing String, Math, Date/Time or FME Feature Functions will have those functions evaluated. Therefore, the names of these functions (in the form @<function_name>) should not be used as literal string values.
These functions manipulate and format strings. | |
Special Characters |
A set of control characters is available in the Text Editor. |
Math functions are available in both editors. | |
Date/Time Functions | Date and time functions are available in the Text Editor. |
These operators are available in the Arithmetic Editor. | |
These return primarily feature-specific values. | |
FME and workspace-specific parameters may be used. | |
Creating and Modifying User Parameters | Create your own editable parameters. |
Dialog Options - Tables
Transformers with table-style parameters have additional tools for populating and manipulating values.
Row Reordering
|
Enabled once you have clicked on a row item. Choices include:
|
Cut, Copy, and Paste
|
Enabled once you have clicked on a row item. Choices include:
Cut, copy, and paste may be used within a transformer, or between transformers. |
Filter
|
Start typing a string, and the matrix will only display rows matching those characters. Searches all columns. This only affects the display of attributes within the transformer - it does not alter which attributes are output. |
Import
|
Import populates the table with a set of new attributes read from a dataset. Specific application varies between transformers. |
Reset/Refresh
|
Generally resets the table to its initial state, and may provide additional options to remove invalid entries. Behavior varies between transformers. |
Note: Not all tools are available in all transformers.
FME Community
The FME Community is the place for demos, how-tos, articles, FAQs, and more. Get answers to your questions, learn from other users, and suggest, vote, and comment on new features.
Search for samples and information about this transformer on the FME Community.