0

I have a input xml like below where I want to extract 'Maker' value and pass it to an element:-

<?xml version="1.0" encoding="UTF-8"?>
<Data xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"                ../../Di/xsd/Doc/Data_0100.xsd">
    <Area>
        <CreationDateTime>2020-11-30T15:47:44Z</CreationDateTime>
        <No>
            <Id1>146520459</Id1>
        </No>
    </Area>
    <text>
        <Catalog>
            <Part>
                <Id>12345</Id>
                <Revision/>
                <Mixer>rtg</Mixer>
            </Part>
            <Dis>
                <Maker>7874</Maker>
            </Dis>
        </Catalog>
    </text>
</Data> 

I tried like below, I need to fetch element2 and pass it as property but no luck:-

import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
import groovy.xml.MarkupBuilder;
def Message processData(Message message) {
     def body = message.getBody()
       
       def root = new XmlSlurper().parseText(body);
       
       def element2 = root.text.Catalog.Dis.Maker;
       message.setProperty("element2", element2.text());
       return message;
}
0

2 Answers 2

1

Correction:

 def body = message.getBody(java.lang.String)
   
Sign up to request clarification or add additional context in comments.

1 Comment

Please add some explanation to your answer such that others can learn from it
1

The path is wrong. Use root.text.Catalog.Dis.Maker instead.

edit

According to OP the actual error is:

Caused by: groovy.lang.MissingMethodException: No signature of method: groovy.util.XmlSlurper.parseText() is applicable for argument types: (ByteArrayInputStream) values: [java.io.ByteArrayInputStream@489dd356]

parseText is used for parsing a String. parse can work with an InputStream.

2 Comments

Hi Thanks, I tried but getting below error:- Caused by: groovy.lang.MissingMethodException: No signature of method: groovy.util.XmlSlurper.parseText() is applicable for argument types: (ByteArrayInputStream) values: [java.io.ByteArrayInputStream@489dd356]
Yeah it's parse and not parseText. Maybe if you would add the actual error you are getting to your question. Also tagging the question with whatever SAP environment you are running this would help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.