Question

I'd like to parse an XML document (SOAP request message) for a particular element. The document is stored in requestContent and looks as follows:

<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:udb="http://somenamespace>
    <soap:Header/>
    <soap:Body>
        <udb:ProvideUDBIdentityInformationRequest>
            <udb:RequestID>1</udb:RequestID>
            <udb:IDnumber>1</udb:IDnumber>
            <udb:UnifiedNumber>3</udb:UnifiedNumber>
        </udb:ProvideUDBIdentityInformationRequest>
    </soap:Body>
</soap:Envelope>

My Groovy code looks like this:

def request = new XmlSlurper().parseText(requestContent)
println request.ProvideUDBIdentityInformationRequest.RequestID

However the output is empty whereas I would have expected a "1".

Thanks, Robert

Was it helpful?

Solution

Can you try:

println request.Body.ProvideUDBIdentityInformationRequest.RequestID

(you also have a " missing from the end of the xml declaration, but I guess that's a cut/paste error?)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top