Skip to main content

XML Assertions

XML matchers perform a structural XML comparison (element order is irrelevant) with optional exclusion of specific elements. An XPath variant lets you pinpoint specific values.


Structural XML match: Then expected record from file based on XML​

Fetches a record and compares its value as XML. Attribute order, whitespace, and element order are normalised before comparison.

Then expected record from file based on XML
| topicAlias | file | excludedElements | expectedRecordKey |
| orders-out | expected.xml | ns:CreationDateTime | |
ColumnTypeRequiredDescription
topicAliasstring✅Alias of a declared output topic
filestring✅Expected XML file path, relative to assets directory
excludedElementsstring❌Comma-separated list of XML element names or XPath expressions to ignore during comparison
expectedRecordKeystring❌Filter: only accept records with this exact key
consumerReadTimeoutinteger❌Max seconds to wait for a record
consumerDeltaTimeinteger❌How far back (seconds) to seek

Excluding elements​

The excludedElements column accepts comma-separated element names (with or without namespace prefix):

| excludedElements |
| CreationDateTime,MessageId,ns2:Checksum |

Elements listed here are removed from both the expected and actual XML before comparison.


XPath match: Then expected record based on XML should have fields matching from file​

Extracts one or more values from the record using XPath expressions and compares them against the corresponding expected file content line-by-line.

Then expected record based on XML should have fields matching from file
| topicAlias | file | xpathExpressions |
| orders-out | expected.xml | //Weight[@unit='KG']/text(),//Sender/ID/text() |
ColumnTypeRequiredDescription
topicAliasstring✅Alias of a declared output topic
filestring✅Expected values file, one expected value per line matching the XPath order
xpathExpressionsstring✅Comma-separated XPath expressions

Expected file format for XPath​

When using multiple XPath expressions, the expected file contains one value per line, in the same order as the expressions:

assets/expected-xpath.txt
42.5
SENDER-001

Avro + XML

XML matchers are not available for Avro topics. Use Avro matchers → for Avro-serialised records.