我想在Smack消息下使用名为 content 的自定义扩展名,如下所示:
<message id="2DCBEFCB-4380-45D7-B188-A26A4F3F4604" type="chat" to="user@myxmppserver.com">
<body>Body text here</body>
<content xmlns="urn:xmpp:content">
<element1 attribute1="some value"></element1>
<element2>some value</element2>
<element3>some other value</element3>
</content>
</message>
我还将收到这种消息。我创建了一个实现ExtensionElement的自定义ContentExtension类:
public class ContentExtension implements ExtensionElement {
public static final String NAMESPACE = "urn:xmpp:content";
public static final String ELEMENT = "content";
@Override
public String getNamespace() {
return NAMESPACE;
}
@Override
public String getElementName() {
return ELEMENT;
}
@Override
public CharSequence toXML(String enclosingNamespace) {
XmlStringBuilder builder = new XmlStringBuilder(this);
//...I will put my child elements here If I somehow get them in the Provider below
builder.closeElement(ELEMENT);
return builder;
}
public static class Provider extends EmbeddedExtensionProvider<ContentExtension> {
@Override
protected ContentExtension createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attributeMap, List<? extends ExtensionElement> content) {
ContentExtension contentExt = new ContentExtension();
// How do I get child elements here with the parameters provided in the function
// I know attributeMap gives the attributes , but how to get the child elements?
// And also how do we get the values inside of the elements NOT the attributes?
return contentExt;
}
}
}