I see the error like "Trying to write END_DOCUMENT when document has no root" while I replace all the payload env and xmlns with "".
It throws error :
Message : "Trying to write END_DOCUMENT when document has no root (ie. trying to output empty document, while writing Xml.
Trace:
at main (Unknown)" evaluating expression: "payload.replaceAll("env:","").replaceAll("xmlns=\"http://decisionresearch.com/RateMaker\"","")".
Element : map_requestFlow/processors/0 @ map_request:map_request.xml:13 (Set Payload)
Element DSL : <set-payload value="#[payload.replaceAll("env:","").replaceAll("xmlns=\"http://decisionresearch.com/RateMaker\"","")]" doc:name="Set Payload" doc:id="7db57e88-dbd4-4a09-ba05-ea37fb9586fc"></set-payload>
Error type : MULE:EXPRESSION
FlowStack : at map_requestFlow(map_requestFlow/processors/0 @ map_request:map_request.xml:13 (Set Payload))
(set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
Mule flow :
<flow name="map_requestFlow" doc:id="21d0d652-3766-47ed-95aa-a451f62c5776" >
<http:listener doc:name="Listener" doc:id="7312114b-2857-40b3-98cd-f52b628b3a28" config-ref="HTTP_Listener_config" path="/map"/>
<set-payload value='#[payload.replaceAll("env:","").replaceAll("xmlns=\"http://decisionresearch.com/RateMaker\"","")]' doc:name="Set Payload" doc:id="7db57e88-dbd4-4a09-ba05-ea37fb9586fc" />
<logger level="INFO" doc:name="Logger" doc:id="21051f39-bb9f-412c-af73-f65051317757" message="#[payload]"/>
</flow>
Input payload : https://github.com/Manikandan99/Map_request/blob/main/soap_request.xml
Expected output : https://github.com/Manikandan99/Map_request/blob/main/soap_response.xml
I am trying to replace payload using
#[payload.replaceAll("env:","").replaceAll("xmlns=\"http://decisionresearch.com/RateMaker\"","")]
Please assist me to resolve this issue.
If you use string operations to work with XML, chances are you are doing it wrong. In other programming languages you should use the existing libraries and frameworks to process XML. In Mule you should use DataWeave transformations. This one is a little bit intuitive because it requires using the seldom used namespace selector. The selector returns the namespace URL, not the name. I created this simple function to remove a namespace from the output:
%dw 2.0
output application/xml
fun removeNamespace(element,namespaceName) =
element mapObject (value, key) ->
(if (key.# as String == namespaceName) (key as String) else (key)) @((key.@)) : (
if (value is Object) removeNamespace(value, namespaceName) else value
)
---
removeNamespace(payload, "http://schemas.xmlsoap.org/soap/envelope/")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With