Description:

Writes a RecordSet to XML. The records are wrapped by a root tag.

Tags:

xml, resultset, writer, serialize, record, recordset, row

Properties:

In the list below, the names of required properties appear in bold. Any other properties (not in bold) are considered optional. The table also indicates any default values, and whether a property supports the Expression Language Guide.

Name

Default Value

Allowable Values

Description

Schema Write Strategy

no-schema * Set 'schema.name' Attribute 
* Set 'avro.schema' Attribute  
* HWX Schema Reference Attributes  
* HWX Content-Encoded Schema Reference
* Confluent Schema Registry Reference 
* Do Not Write Schema 
Specifies how the schema for a Record should be added to the data.
Schema Cache

Controller Service API: 


RecordSchemaCacheService

Implementation: 

VolatileSchemaCache


Specifies a Schema Cache to add the Record Schema to so that Record Readers can quickly lookup the schema.

Schema Access Strategy

inherit-record-schema * Use 'Schema Name' Property 
* Inherit Record Schema 
* Use 'Schema Text' Property 
Specifies how to obtain the schema that is to be used for interpreting the data.
Schema Registry

Controller Service API: 


SchemaRegistry

Implementations: 

ConfluentSchemaRegistry


AvroSchemaRegistry


HortonworksSchemaRegistry


Specifies the Controller Service to use for the Schema Registry
Schema Name ${schema.name} Specifies the name of the schema to lookup in the Schema Registry property

Supports Expression Language: true (will be evaluated using flow file attributes and variable registry)


Schema Version Specifies the version of the schema to lookup in the Schema Registry. If not specified then the latest version of the schema will be retrieved.

Supports Expression Language: true (will be evaluated using flow file attributes and variable registry)


Schema Branch Specifies the name of the branch to use when looking up the schema in the Schema Registry property. If the chosen Schema Registry does not support branching, this value will be ignored.

Supports Expression Language: true (will be evaluated using flow file attributes and variable registry)


Schema Text ${avro.schema} The text of an Avro-formatted Schema

Supports Expression Language: true (will be evaluated using flow file attributes and variable registry)


Date Format Specifies the format to use when reading/writing Date fields. If not specified, Date fields will be assumed to be number of milliseconds since epoch (Midnight, Jan 1, 1970 GMT). If specified, the value must match the Java Simple Date Format (for example, MM/dd/yyyy for a two-digit month, followed by a two-digit day, followed by a four-digit year, all separated by '/' characters, as in 01/01/2017).
Time Format Specifies the format to use when reading/writing Time fields. If not specified, Time fields will be assumed to be number of milliseconds since epoch (Midnight, Jan 1, 1970 GMT). If specified, the value must match the Java Simple Date Format (for example, HH:mm:ss for a two-digit hour in 24-hour format, followed by a two-digit minute, followed by a two-digit second, all separated by ':' characters, as in 18:04:15).
Timestamp Format Specifies the format to use when reading/writing Timestamp fields. If not specified, Timestamp fields will be assumed to be number of milliseconds since epoch (Midnight, Jan 1, 1970 GMT). If specified, the value must match the Java Simple Date Format (for example, MM/dd/yyyy HH:mm:ss for a two-digit month, followed by a two-digit day, followed by a four-digit year, all separated by '/' characters; and then followed by a two-digit hour in 24-hour format, followed by a two-digit minute, followed by a two-digit second, all separated by ':' characters, as in 01/01/2017 18:04:15).

Suppress Null Values

never-suppress * Never Suppress 
* Always Suppress 
* Suppress Missing Values 
Specifies how the writer should handle a null field

Pretty Print XML

false * true
* false
Specifies whether or not the XML should be pretty printed
Name of Root Tag Specifies the name of the XML root tag wrapping the record set. This property has to be defined if the writer is supposed to write multiple records in a single FlowFile.
Name of Record Tag Specifies the name of the XML record tag wrapping the record fields. If this is not set, the writer will use the record name in the schema.

Wrap Elements of Arrays

no-wrapping * Use Property as Wrapper 
* Use Property for Elements 
* No Wrapping 
Specifies how the writer wraps elements of fields of type array
Array Tag Name Name of the tag used by property "Wrap Elements of Arrays" to write arrays

Character Set

UTF-8 The Character set to use when writing the data to the FlowFile

State management:

This component does not store state.

Restricted:

This component is not restricted.

System Resource Considerations:

None specified.

Summary:

The XMLRecordSetWriter Controller Service writes record objects to XML. The Controller Service must be configured with a schema that describes the structure of the record objects. Multiple records are wrapped by a root node. The name of the root node can be configured via property. If no root node is configured, the writer expects only one record for each FlowFile (that will not be wrapped). As Avro does not support defining attributes for records, this writer currently does not support writing XML attributes.

Example: Simple records

            RecordSet (
              Record (
                Field "name1" = "value1",
                Field "name2" = 42
              ),
              Record (
                Field "name1" = "value2",
                Field "name2" = 84
              )
            )

This record can be described by the following schema:
{
“name”: “test”,
“namespace”: “nifi”,
“type”: “record”,
“fields”: [
{ “name”: “name1”, “type”: “string” },
{ “name”: “name2”, “type”: “int” }
]
}

Assuming that “root_name” has been configured as the name for the root node and “record_name” has been configured as the name for the record nodes, the writer will write the following XML:
<root_name>
<record_name>
<name1>value1</name1>
<name2>42</name2>
</record_name>
<record_name>
<name1>value2</name1>
<name2>84</name2>
</record_name>
</root_name>

The writer furthermore can be configured how to treat null or missing values in records:
RecordSet (
Record (
Field “name1” = “value1”,
Field “name2” = null
),
Record (
Field “name1” = “value2”,
)
)

If the writer is configured always to suppress missing or null values, only the field of name “name1” will appear in the XML. If the writer ist configured only to suppress missing values, the field of name “name2” will appear in the XML as a node without content for the first record. If the writer is configured never to suppress anything, the field of name “name2” will appear in the XML as a node without content for both records.

Example: Arrays

The writer furthermore can be configured how to write arrays:
RecordSet (
Record (
Field “name1” = “value1”,
Field “array_field” = [ 1, 2, 3 ]
)
)

This record can be described by the following schema:
{
“name”: “test”,
“namespace”: “nifi”,
“type”: “record”,
“fields”: [
{ “name”: “array_field”, “type”:
{ “type”: “array”, “items”: int }
},
{ “name”: “name1”, “type”: “string” }
]
}

If the writer is configured not to wrap arrays, it will transform the record to the following XML:
<root_name>
<record_name>
<name1>value1</name1>
<array_field>1</array_field>
<array_field>2</array_field>
<array_field>3</array_field>
</record_name>
</root_name>

If the writer is configured to wrap arrays using the field name as wrapper and “elem” as tag name for element nodes, it will transform the record to the following XML:
<root_name>
<record_name>
<name1>value1</field2>
<array_field>
<elem>1</elem>
<elem>2</elem>
<elem>3</elem>
</array_field>
</record_name>
</root_name>

If the writer is configured to wrap arrays using “wrap” as wrapper and the field name as tag name for element nodes, it will transform the record to the following XML:
<root_name>
<record_name>
<name1>value1</field2>
<wrap>
<array_field>1</array_field>
<array_field>2</array_field>
<array_field>3</array_field>
</wrap>
</record_name>
</root_name>