The xmlContentFilter removes certain XML elements from message bodies. The elements are described using an XPath expression.
Explanation:
If the XPath expression is simple enough, a StAX-Parser is used to determine whether the XPath might match a message at all. This can improve performance significantly, as a DOM tree does probably not have to to be constructed for every message. This is, for example, the case in
If the message body cannot be parsed, e.g. because it is not well-formed XML or contains a DOCTYPE, the message is rejected: with status 400 in the request flow and 500 in the response flow. An empty body is left unchanged, and so is a body whose Content-Type declares another format, such as JSON or form data, unless it starts like XML: such a body is filtered, or rejected if it cannot be parsed. If the message is XOP-encoded, the XPath-expression is run on the reconstituted message; if it matches, the message is replaced by the modified reconstituted message.
Example Configuration
api:
port: 2000
flow:
- response:
- xmlContentFilter:
xPath: //book/reviews
target:
url: https://membrane-api.io
api:
port: 2000
flow:
- response:
- xmlContentFilter:
xPath: //book/reviews
target:
url: https://membrane-api.io
Syntax
xmlContentFilter:
xPath: <string> # requiredxmlContentFilter: xPath: <string> # required
Attributes
| Name | Required | Default | Description | Examples |
|---|---|---|---|---|
| xPath | true | - | An XPath 1.0 expression describing the elements to be removed from message bodies. | - |