After a little bit of digging, I found the parsing code in ItemProvider, where I can see the parser provides the element name and namspace. It then gets the “payload” on line 61
CharSequence payloadText = PacketParserUtils.parseElement(parser, true);
Which returns the whole outer element. This could perhaps be replaced by PacketParserUtils.parseContent().
Then, I think SimplePayload should have
public CharSequence getPayload()
And the toXML() should construct the outer element around the payload. That way you can get the inner and outer XML out.
Nevertheless, this would leave the constuctor as a breaking change for any existing client code !
There’s no easy solution to this, I think…
I should probably keep quiet now, and go and implement my own ExtensionElementProvider