// copy the payload
XMLStreamReader clone;
if(hasPayload()) {
assert unconsumed();
consumedAt = null; // but we don't want to mark it as consumed
MutableXMLStreamBuffer xsb = new MutableXMLStreamBuffer();
//the boolean value tells the first body part is written.
//based on this we do the right thing
StreamReaderBufferCreator c = new StreamReaderBufferCreator(xsb);
// preserving inscope namespaces from envelope, and body. Other option
// would be to create a filtering XMLStreamReader from reader+envelopeTag+bodyTag
c.storeElement(envelopeTag.nsUri, envelopeTag.localName, envelopeTag.prefix, envelopeTag.ns);
c.storeElement(bodyTag.nsUri, bodyTag.localName, bodyTag.prefix, bodyTag.ns);
// Loop all the way for multi payload case
while(reader.getEventType() != XMLStreamConstants.END_DOCUMENT){
String name = reader.getLocalName();
String nsUri = reader.getNamespaceURI();
if(name.equals("Body") && nsUri.equals(soapVersion.nsUri) || (reader.getEventType() == XMLStreamConstants.END_DOCUMENT))
break;
c.create(reader);
// Skip whitespaces in between payload and </Body> or between elements
if (reader.isWhiteSpace()) {
XMLStreamReaderUtil.nextElementContent(reader);
}
}
XMLStreamReaderUtil.readRest(reader);
XMLStreamReaderUtil.close(reader);
XMLStreamReaderFactory.recycle(reader);
reader = xsb.readAsXMLStreamReader();
clone = xsb.readAsXMLStreamReader();
// advance to the start tag of the first element
proceedToRootElement(reader);
proceedToRootElement(clone);
} else {