I’m writing code to publish an item to a pubsub node, with a payload. Something like Example 99 found here.
So I’m using code like this :-
SimplePayload Payload = new SimplePayload( “entry”, “Atom Syndication Format namespace”, “<stuff>a payload</stuff>” );
PayloadItem<SimplePayload> MessageItem = new PayloadItem<>(Payload);
LeafNode Node = m_PubSubManager.getLeafNode( “My Node Name” );
Node.publish( MessageItem );
But, so far as I can see SimplePayload does nothing with the elementName and namespace parameters that are passed to it. The toXML function just returns the payload.
<stuff>a payload</stuff>
So, I was wondering what the intention was for this class. At the moment it does little more than hold on to a CharSequence. But maybe I’m missing the point.
I had been expecting it to generate an XML element with the given name and namespace, and insert the payload as it’s content. i.e.
Afaiu you are supposed to hand over valid xml to the SimplePayload class. The name and namespace are supposed to be equal to the name and namespace of the content you pass it. So in your case you would call it like this:
SimplePayload Payload = new SimplePayload(“entry”, “http://www.w3.org/2005/Atom”,
“<entry xmlns=‘http://www.w3.org/2005/Atom’><stuff>a payload</stuff></entry>”);
Just to be clear, I had expected it to build the XML using the element name and namespace, making the passed “payload” string the internal contents of that element. It would still need to be “correctly fomatted XML” - including being a simple string.
As a client/user of SimplePayload, when constructing a pubsub message to be sent, I know which element I want to use. At least in my use case.
It seems that SimplePayload is used as the default to hold a payload when a pubsub item is received from a node, and that the element and namespace are entered, so I presume they are parsed to this level. But I have yet to track down the source code where this happens.
I don’t think SimplePayload should have to parse any XML itself. That would make it complex !
Also, I just spotted the SimplePayload usage here at the end of the “Publishing to a node” section - that will need an update, depending on what happens to the code…
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