0

I've read through the documentation, but can't get this working. What I'm trying to do is parse this XML string

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
    <soapenv:Body>
        <soapenv:Fault>
            <faultcode>soapenv:Server</faultcode>
            <faultstring>TriggeredMessageFault</faultstring>
            <detail>
                <TriggeredMessageFault xmlns="urn:fault.domain.com">
                    <exceptionCode>INVALID_PARAMETER</exceptionCode>
                    <exceptionMessage>Invalid campaign object</exceptionMessage>
                </TriggeredMessageFault>
            </detail>
        </soapenv:Fault>
    </soapenv:Body>
</soapenv:Envelope>

What I'm trying to do is get to exceptionCode and exceptionMessage and store those in two different variables.

1 Answer 1

2

I actually figured out how to do this finally

def xmlstring = """<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
    <soapenv:Body>
        <soapenv:Fault>
            <faultcode>soapenv:Server</faultcode>
            <faultstring>TriggeredMessageFault</faultstring>
            <detail>
                <TriggeredMessageFault xmlns="urn:fault.domain.com">
                    <exceptionCode>INVALID_PARAMETER</exceptionCode>
                    <exceptionMessage>Invalid campaign object</exceptionMessage>
                </TriggeredMessageFault>
            </detail>
        </soapenv:Fault>
    </soapenv:Body>
</soapenv:Envelope>"""

def soap_ns = new groovy.xml.Namespace("http://schemas.xmlsoap.org/soap/envelope/",'soapenv')
def root = new XmlParser().parseText(xmlstring)
println root[soap_ns.Body][soap_ns.Fault].detail.TriggeredMessageFault.exceptionMessage.text()

My issue was twofold. I didn't know that after loading it started at Envelope and I wasn't sure how to deal with the namespace.

Sign up to request clarification or add additional context in comments.

Comments

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.