Loading

APIKIT:BAD_Request - An invalid XML character (Unicode: 0x2) was found in the element content of the document

Publiceringsdatum: Aug 19, 2025
Beskrivning

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.

XML specification standards

 

 

Lösning

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" />
Knowledge-artikelnummer

005132388

 
Laddar
Salesforce Help | Article