Description:
This processor evaluates one or more XQueries against the
content of FlowFiles. The results of those XQueries are assigned to
FlowFile attributes or are written to the content of the FlowFile
itself, depending on how the user configures the Destination property
in the processor. One attribute or FlowFile is produced for each XQuery
result. Each produced FlowFile will carry the attributes of the input
FlowFile. See the "Examples" section for details on how
multiple results can be wrapped or concatenated. XQueries are
entered by adding user-defined
properties; the name of each user-added property maps to the attribute
name into which the result should be placed. The value of the property
must be a valid XQuery expression.
Properties:
In the list below, the names of required properties
appear in bold. Any other properties (not in bold) are considered
optional. If a property has a default value, it is indicated. If a
property supports the use of the NiFi Expression Language (or
simply, "expression language"), that is also indicated.
Modifies Attributes:
This processor adds user-defined attributes if the
<Destination> property is set to flowfile-attribute
.
- Destination
- Indicates whether the results of the XQuery evaluation
are written to the FlowFile content or a FlowFile attribute; if using
attribute, the attribute's name must be specified in the value of the
Attribute Name property.
- Valid values are:
- flowfile-content
- flowfile-attribute
- Default value: flowfile-content
- Supports expression language: false
- Output: Method
- Identifies the overall method that should be used for
outputting a result tree. This property will be ignored if the result
of the XQuery is not a DOCUMENT or ELEMENT Node.
- Valid values are:
- Default value: xml
- Supports expression language: false
- Output: Omit XML Declaration
- Specifies whether the processor should output an XML
declaration when transforming a result tree. This property will be
ignored if the result of the XQuery is not a DOCUMENT or ELEMENT Node.
- Valid values are:
- Default value: false
- Supports expression language: false
- Output: Indent
- Specifies whether the processor may add additional
whitespace when outputting a result tree. This property will be ignored
if the result of the XQuery is not a DOCUMENT or ELEMENT Node.
- Valid values are:
- Default value: false
- Supports expression language: false
- user-defined properties
- The name of the attribute to put the XQuery result into
if flowfile-attribute is used as the value for the Destination
property; if using flowfile-content as the value for the Destination
property, this value is ignored.
- Supports expression language: false
Relationships:
- failure
- If the XQuery cannot be evaluated against the content
of the FlowFile, then the FlowFile follows this relationship. For
example, if the FlowFile does not contain valid XML.
- matched
- If the XQuery is successfully evaluated and the
FlowFile is modified as a result, then the FlowFile follows this
relationship.
- unmatched
- If the XQuery does not match the content of the
FlowFile, then the FlowFile follows this relationship.
Examples:
This processor produces one attribute or FlowFile per
XQueryResult. If only one attribute or FlowFile is desired, the following
examples demonstrate how this can be achieved using the XQuery
language. The examples below reference the following sample XML:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="foo.xsl"?>
<ns:fruitbasket xmlns:ns="http://namespace/1">
<fruit taste="crisp">
<!-- Apples are my favorite-->
<name>apple</name>
<color>red</color>
</fruit>
<fruit>
<name>apple</name>
<color>green</color>
</fruit>
<fruit>
<name>banana</name>
<color>yellow</color>
</fruit>
<fruit taste="sweet">
<name>orange</name>
<color>orange</color>
</fruit>
<fruit>
<name>blueberry</name>
<color>blue</color>
</fruit>
<fruit taste="tart">
<name>raspberry</name>
<color>red</color>
</fruit>
<fruit>
<name>none</name>
<color/>
</fruit>
</ns:fruitbasket>
-
XQuery to return all "fruit" nodes individually (7 Results):
-
XQuery to return only the first "fruit" node (1 Result):
-
XQuery to return only the last "fruit" node (1 Result):
-
XQuery to return all "fruit" nodes, wrapped in a "basket" tag (1 Result):
- <basket>{//fruit}</basket>
-
XQuery to return all "fruit" names individually (7 Results):
-
XQuery to return only the first "fruit" name (1 Result):
-
XQuery to return only the last "fruit" name (1 Result):
- //fruit[count(//fruit)]/text()
-
XQuery to return all "fruit" names as a comma separated list (1 Result):
- string-join((for $x in //fruit return $x/name/text()), ', ')
-
XQuery to return all "fruit" colors and names as a comma separated list (1 Result):
- string-join((for $y in (for $x in //fruit return string-join(($x/color/text() , $x/name/text()), ' ')) return $y), ', ')
-
XQuery to return all "fruit" colors and names as a comma separated list (1 Result):
- string-join((for $y in (for $x in //fruit return string-join(($x/color/text() , $x/name/text()), ' ')) return $y), ', ')
-
XQuery to return all "fruit" colors and names as a new line separated list (1 Result):
- string-join((for $y in (for $x in //fruit return string-join(($x/color/text() , $x/name/text()), ' ')) return $y), '\n')