Soap with attachments using Java SAAJ problem

From: Frank <>
Date: Mon, 18 Apr 2005 08:23:41 -0400

Not entirely sure this is the best users group for java SAAJ questions
but did not see a better one.

I have Been trying to learn how to create and receive soap messages
using java's SAAJ API. I have been having a problem after reading in a
soap message being ale to parse it out into it's pieces parts. I see
some code that allows me to do it from a file but I have a SOAPMessage
type that was read in from the network and it would be silly to save to
a file too read back in. But I did find some other example code that
seems to do what I want it to do. I want to get the values of any given
element in the document, should be no big deal right?

I got the exampl from here:

the code snipit is below

           SOAPPart sp = reply.getSOAPPart();
            SOAPEnvelope se = sp.getEnvelope();
            SOAPBody sb = se.getBody();


            Name name = se.createName("SECRET");
            java.util.Iterator it = sb.getChildElements(name);

            while (it.hasNext())
              Object o =;
              System.out.println("The class of " + o +
                            " is " + o.getClass().getName());

              if (o instanceof SOAPBodyElement)
                SOAPBodyElement bodyElement = (SOAPBodyElement) o;
                String ele = bodyElement.getValue();
                System.out.print("Element: ");
                  System.out.println("\n not a SOAPBodyElement");

The soap Message is as follows:
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="">

The output is as follows:

The class of [SECRET: null] is