Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.5k views
in Technique[技术] by (71.8m points)

dataweave - Trying to write END_DOCUMENT when document has no root (ie. trying to output empty document, while writing Xml at 1| %dw 2.0

I see the error like "Trying to write END_DOCUMENT when document has no root" while I use the mentioned

Script:

%dw 2.0 
output application/xml
ns ns0 urn:astrazeneca:na:Activity:domain:3 
---
payload.ns0#Interactions.ns0#Interaction.ns0#InteractionId.ns0#ID 

Input:

<Interactions>
    <Interaction>
        <InteractionId>
            <ID SystemCode="VNA">a044U00002GXVN1QAP</ID>
        </InteractionId>
        <InteractionDetails ></InteractionDetails>
        <Activity CreatedOnDate="2021-01-04T18:13:15">
            <ActivityId>
                <ns2:ID SystemCode="VNA">a084U00001dFR7aQAG</ns2:ID>
            </ActivityId>
        </Activity>
    </Interaction>
</Interactions>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

There is missing information and the example input doesn't match the script to be sure, however it looks like the script is trying to output a single value ("a044U00002GXVN1QAP") in XML format. That is invalid because a string is not a valid XML. You need to define a root element in the output so it can generate a valid XML.

Example (removing namespace for simplicity):

%dw 2.0 
output application/xml
---
{ someRoot: payload.Interactions.Interaction.InteractionId.ID }

Output:

<?xml version='1.0' encoding='UTF-8'?>
<someRoot>a044U00002GXVN1QAP</someRoot>

If you are just trying to output that id to be processed later in the flow just change the output to application/java instead so it doesn't require a root element and it is much more efficient, avoiding the extra XML formatting/parsing.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...