Lightweight XMPP library.
- RFC-6120 - Core
- XEP-0004 - Data Forms
- XEP-0012 - Last Activity
- XEP-0030 - Service Discovery
- XEP-0045 - Multi User Chat
- XEP-0047 - In-Band Bytestreams
- XEP-0085 - Chat States Notifications
- XEP-0172 - User Nickname
- XEP-0199 - Ping
- XEP-0202 - Entity Time
- XEP-0203 - Delayed Delivery
After XMPP# v6.0 we are using libexpat as default XML parser for xmpp protocol. But additional parsers can be implemented along with the lib.
You can still use older XMPP# version that includes builtin XMPP parser using XmlReader
or use XMPP# Tokenizer package.
The class XmppSharp.Dom.XmppDocument
was keep to provide basic XML parsing from file or string in a simple and fast way using .NET's XmlReader
.
The XmppElementFactory
class registers and maintains the mapping of all XML elements to their respective classes. Each element is qualified by a name (Tag name) and its namespace URI, when registered the parser will obtain this information and construct the class corresponding to the XML element. If the mapping does not exist, it will use a fallback by constructing an instance of XmppSharp.Dom.XmppElement
.
Consider the example table below demonstrating how this mapping works:
Qualified Tag Name | Namespace(s) | Mapped Class |
---|---|---|
iq | see note below | XmppSharp.Protocol.Core.Iq |
message | see note below | XmppSharp.Protocol.Core.Message |
presence | see note below | XmppSharp.Protocol.Core.Presence |
error | see note below | XmppSharp.Protocol.Base.StanzaError |
starttls | urn:ietf:params:xml:ns:xmpp-tls | XmppSharp.Protocol.Tls.StartTls |
success | urn:ietf:params:xml:ns:xmpp-sasl | XmppSharp.Protocol.Sasl.Success |
stream:features | http://etherx.jabber.org/streams | XmppSharp.Protocol.Base.StreamFeatures |
... | ... | ... |
Note
Some cases like iq
, message
, presence
, error
(error element inside an stanza), have more than one namespace defined (because it depends on each specific namespace URI), but they are declared in the same way. The difference is that more than one namespace is assigned to this element, so the XmppElementFactory
can correctly map which one it will instantiate.
Defining your XML elements is simple, just create a class that inherits the base class XmppSharp.Dom.XmppElement
or similar, call the base constructor of the class to initialize the tag name correctly. And add the attribute [XmppTag(tagName, namespace)]
for each desired tag and namespace and register the type by calling XmppElementFactory.RegisterType
(or to register an entire assembly XmppElementFacotry.RegisterAssembly
), eg:
// define xmpp tags
[XmppTag("bind", Namespaces.Bind)]
public class Bind : XmppElement
{
public Bind() : base("bind", Namespaces.Bind) // call base constructor to setup this element instance.
{
// setup other properties...
}
}
Due internal reasons we merged expat parser into main package. We no longer provide default parser using XmlReader