The user encountered an error 'An invalid XML character (Unicode: 0x2) was found in the element content of the document' while processing an XML payload in the API Kit router. The issue arises due to the presence of an invalid ASCII control character in the payload, which violates XML specification rules.
1. Sanitise the XML payload by removing invalid ASCII control characters, such as Unicode: 0x2, before processing it.
2. Validate the sanitised XML payload against the XSD schema to ensure compliance with the defined rules.
Below is the sample code used for sanitising the XML payload.
<http:listener config-ref="apikit-bad-request-httpListenerConfig" path="/api/*">
<http:response statusCode="#[vars.httpStatus default 200]">
<http:headers>#[vars.outboundHeaders default {}]</http:headers>
</http:response>
<http:error-response statusCode="#[vars.httpStatus default 500]">
<http:body>#[payload]</http:body>
<http:headers>#[vars.outboundHeaders default {}]</http:headers>
</http:error-response>
</http:listener>
<set-payload value="#[payload]" doc:name="Set Payload" doc:id="ef784dfe-491b-4b14-9f9f-1e77652809d7" mimeType="text/plain"/>
<ee:transform doc:name="remove unwanted characters" doc:id="c15707ee-4ebd-4b31-addf-9467acf5aa20" >
<ee:message >
<ee:set-payload ><![CDATA[%dw 2.0
output text/plain
---
(payload replace(/\u0002/) with "")]]></ee:set-payload>
</ee:message>
</ee:transform>
<set-payload value="#[payload]" doc:name="Set Payload to XML" doc:id="3bfd308d-43cb-4e85-bbbe-9e65185dcc89" mimeType="application/xml"/>
<apikit:router config-ref="apikit-bad-request-config" />005132388

We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply. Click on the different cookie categories to find out more about each category and to change the default settings.
Privacy Statement
Required cookies are necessary for basic website functionality. Some examples include: session cookies needed to transmit the website, authentication cookies, and security cookies.
Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.
Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.