Thanks for the response. But, no, I'm not confused. Given an XML document Body.unmarshall can accept that XML and create a Body object from it. BUT again it throws away the root element of the passed in xml - according to what you've said - the reason for this is that it needs to be able to accept the xml created from a Body.marshall call. So that means that Body.unmarshall really does expect that the root element is the SOAP:Body element... (Yes, I have been calling unmarshall without having the root element be the SOAP:Body tag). Looking at the source, unmarshall method doesn't check to see if the root element is the SOAP:Body element - but just gets rid of whatever root element there is...
This being the case it seems like we could add some convenience methods to Body (or elsewhere) to help with marshalling and unmarshalling: 1) a different unmarshall method that accepts an xml doc without throwing away the root element 2) get the Fault (if one exists) 3) get the Document of the body (disregarding any SOAP elements - like Body and Fault) Thanks > -----Original Message----- > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] > Sent: Thursday, February 14, 2002 12:22 PM > To: [EMAIL PROTECTED] > Subject: RE: Body.marshall and Body.unmarshall confusion > [Virus Checked] > > > OK, I think you have unmarshall and marshall backwards. > Unmarshall creates a > Body object from an XML representation. Marshall creates an > XML representation > from an object. Marshall does add body tags. Unmarshall does > remove them. > > Think about it like this: Unmarshall needs to be able to make > an object from > whatever is output from Marshall. That's what they are for - > to marshall and > unmarshall the object for wire transfer using SOAP. The > marshall includes the > body tags because they are needed, and its a logical place to > put that code. If > it didn't, the envelope would have to do it, and that is really less > encapsulation. This way the body object is totally and solely > responsible for > generating the correct XML for a SOAP body. > > That's why unmarshall throws away the root element - because > it is not needed to > get the actual values for the Body object. The simple > existence of a Body object > is equivalent to a Body tag. > > Why doesn't it check for the Body tag? Because the purpose of > the method is to > take an XML SOAP body and make an object, not to take > arbitrary XML and make an > object. This is not a buildFromXML method for general > purposes, it has the > specific intent of translating SOAP XML to an object > representation. And > frankly, if it were my code I would argue against the > inclusion of such a check > on performance grounds. Nearly 100% of the time the method > will be called as it > expects to be called (_all_ RPC code, for example), and > that's the case it > should be coded for. > > If you call unmarshall without the body tags in the XML > you're lucky not to get > an exception, to say nothing of unusual behavior. > > S- > > > > > > "Rafert, Tim" <[EMAIL PROTECTED]> on 02/14/2002 11:27:24 AM > > Please respond to [EMAIL PROTECTED] > > To: "'[EMAIL PROTECTED]'" <[EMAIL PROTECTED]> > cc: (bcc: Steve Salkin/3rd/US/AON) > > Subject: RE: Body.marshall and Body.unmarshall confusion > [Virus Checked] > > > I understand what you're saying, but I don't understand why > Body.unmarshall() throws out the root element of what you are > passing in. I > expected unmarshall to automatically add the Body tag to > whatever XML I > passed to it (which it does). But I surely did not expect it > to remove the > root element to whatever I sent it. That's why I'm wondering > if unmarshall > expects to get the body tag as the root element? But then I > would think it > better for the method to check if the root element is the > body tag - if so > do NOTHING, if not then just add in the body tag... > > Second, if Body.unmarshall automatically adds the body tag - > then it seems > logical that Body.marshall should automatically remove it??? > > Just trying to figure out the reasoning behind this... > > Thanks > > > -----Original Message----- > > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] > > Sent: Thursday, February 14, 2002 8:03 AM > > To: [EMAIL PROTECTED] > > Subject: Re: Body.marshall and Body.unmarshall confusion > > [Virus Checked] > > > > > > The reason why Body has marshall() and unmarshall() methods > > is so that an object > > of that type can be converted to XML as specified in the SOAP > > protocol. So when > > you marshall() a Body you should expect it to generate a > > valid SOAP body in XML. > > The unmarshall() method is to allow a Body object to be > > created from SOAP XML > > that arrives over the wire. This particular implementation > > expects the calling > > code to separate the whole body subpart from the message and > > hand it to the > > unmarshall() method. It's that simple. The intelligence to > > handle the body > > subpart is contained in the Body class. > > > > Now, this is not the most convenient thing for people working > > at the messaging > > level, but it's not too bad either - just put SOAP body tags > > around the things > > you are using to load the body. That makes sense in a way, > > you're loading the > > body just as if your strings had just arrived off the wire. > > > > Does that answer your question? > > > > S- > > > > > > > > > > > > "Rafert, Tim" <[EMAIL PROTECTED]> on 02/13/2002 07:35:20 PM > > > > Please respond to [EMAIL PROTECTED] > > > > To: "'[EMAIL PROTECTED]'" <[EMAIL PROTECTED]> > > cc: (bcc: Steve Salkin/3rd/US/AON) > > > > Subject: Body.marshall and Body.unmarshall confusion > [Virus Checked] > > > > > > > > I'm still very confused by the Body.unmarshall() and now > > also Body.marshall(). > > > > With unmarshall - I still don't understand why it is > > throwing out the root > > element of the xml... > > > > > > > >
