This specification defines a protocol for collaboratively editing XML data. Essentially, this protocol provides a simple way of synchronizing an unordered set of records across several endpoints. Additionally, this protocol defines a mapping between such a set of records and the Document Object Model (DOM).
A special feature of this protocol compared to most other collaborative editing tools is that no master or server entity is required. A Multi-User Chat (XEP-0045)  component or specialized editing component can be used for sessions that have a large number of participants, that need to be persistent, or that require more granular access control. However, the client implementation is minimally different whether such a specialized component is used or whether the session is one-to-one or multi-user.
Requirements for shared editing are provided in Requirements for Shared Editing (XEP-0228) .
GUID: a Globally Unique Indentifier, used as the identifier for a shared editing session.
Host: The JID to which the SXE messages are sent for relaying to other members of the session; this can be the initiator of the session (e.g., in a one-to-one session or small multi-user session) or a multi-user chat room or specialized shared editing component.
RID: the Record ID given to a record when it is created.
State: In the context of a new user joining, the state refers to the set of records that describes the edited object, including all previous versions of each record. All entities involved in the session are REQUIRED to keep this state unless a specialized component handles user joins.
Weight: Primarily, the weight of a node is represented by the 'primary-weight' field of the corresponding record. Secondarily, if the values of the 'primary-weight' of two records are equal, the first differing characters of the rids are compared by their Unicode values. The higher the character the higher the weight of the node is.
When used in the context of XMPP, Shared XML Editing relies on Jingle (XEP-0166)  for overall session management. In Jingle terms, SXE defines a "transport method" that can be used for multiple "application types" such as XHTML documents, SVG whiteboards, Collaborative Data Objects (XEP-0204) , or any other XML data format.
In order to initiate a shared editing session, one party sends a Jingle session-initiate request to another party. Here the <transport/> element indicates support for exchanging SXE information over XMPP and the <description/> element indicates support for editing of XHTML documents (this application type has not been defined yet and is used here only as an example). The <transport/> element MUST include at least one <host/> element that specifies the entity that serves as the host for the session. The host can be the initiator of the session (and must be for a one-to-one session) or a multi-user chat room or specialized reflector where the session is hosted.
The responder immediately acknowledges receipt of the session-initiate.
In order to definitively accept the session, the responder sends a session-accept to the initiator.
The initiator immediately acknowledges receipt of the session-accept.
In order to decline the session, the responder sends a session-terminate to the initiator.
The responder indiciates the reason for refusing the session by including a "reason" element. The following reasons are suggested (see also XEP-0166):
The initiator immediately acknowledges receipt of the session-terminate.
Before connecting to a session, a party MUST determine the Service Discovery (XEP-0030)  identity and supported features of the host. In many situations the party already knows this information (e.g., if the host is the initiator of the Jingle session). In other situations the party will need to send a service discovery information request to the host.
If the host supports Shared XML Editing over XMPP, it MUST return features of "urn:xmpp:sxe:0" and "urn:xmpp:jingle:transports:sxe" (see Protocol Namespaces regarding issuance of one or more permanent namespaces):
An entity that is engaged in a session can advertise that fact by including the session id and descriptive name in its XMPP presence.
Such presence can be broadcast or can be sent in the context of a multi-user chat room (see XEP-0045).
However, presence is not sent when operating in a serverless messaging environment (see XEP-0174). Instead, DNS TXT records are published. Two new key-value pairs are used to advertise a session id ("sxe_id") and session name ("sxe_name") when using serverless messaging.
In order to synchronize its local state with the existing state of the edited object, an entity sends a connection request to the host. The identity learned through service discovery determines what kind of message the joining party sends (e.g., type='groupchat' if the host is a MUC room).
To connect to a session, the joiner MUST send an SXE <connect/> element to the host.
When a joining user sends a connect request, the joiner must retrieve the state of the session from an existing participant. The following ruules apply:
The state offer MUST contain the <description/> element or elements that were included in the Jingle session-initiate request.
The joiner accepts a state offer by sending an <accept-state/> element to one of the entities that offer to send the state. The joiner MUST store all the <sxe/> elements it receives after the <state-offer/> element it decides to accept. It MUST also abort the negotiation with the other users that offered to send the state.
Once the other entity receives the <accept-state/> element it MUST proceed sending the state as described in the next section.
If a multiple state offers were received, one should be accepted and the others should be refused by sending a <refuse-state/> element.
The process of sending the state is following:
The state can be sent in any number of <sxe/> elements but the user sending the state MUST NOT send any new <sxe/> elements between sending the <document-begin/> (i.e. taking the snapshot) and the <document-end/> element.
The state SHOULD include a version of each element that was synchronized, and hence won't be undone, as well as all the later versions. In practice this can often be impossible to know in a session without a specialized MUC component so it may be safest to send version 0 and all the later edits to each element. Version 0 is implied if the version element is missing.
If the session is already in progress, the entity sends the snapshot.
Once a participant has received initial state, he can participate in the editing session.
Here is another edit in the session.
This basic editing session results in the following XML.
All SXE elements MUST be contained in a <sxe/> element. This element MUST posess the following attributes:
|xmlns||REQUIRED and MUST be "urn:xmpp:sxe:0"|
|session||REQUIRED and MUST be a GUID of the session.|
|id||REQUIRED and MUST be unique within the set of <sxe/> elements sent by the user to the session.|
The prolog of the XML document cannot be edited after the session has been established.
If an XML Schema Definition is specified for the document and the processing of an <sxe/> element results in a noncompliant document, the receiving client SHOULD reply with edits that effectively undo the offending edits. TODO: the offending client should probably be notified.
A record contains the following fields and corresponds to a single DOM node:
|Field Name||Mutable||Applies to nodes of type||Description|
|rid||no||all||The GUID of the record.|
|type||no||all||The type of DOM node (element, attr, etc.).|
|version||Indirectly||all||The current version of the record.|
|parent||yes||all||The record id of the record corresponding to the parent node.|
|primary-weight||yes||all||The primary weight used to determine the order of sibling nodes corresponding to the records.|
|ns||yes (TODO: is this reasonable?)||element, attr||The namespace of the element or attribute|
|name||yes (TODO: is this reasonable?)||element, attr||The name of the element or attribute.|
|chdata||yes||text, attr, comment||The content of a text node or a comment or the value of the attribute.|
|pitarget||yes (TODO: is this reasonable?)||proccessinginstruction||The target of the processing instruction.|
|pidata||yes||proccessinginstruction||The data of the processing instruction.|
Whenever a record is added, modified, or removed, the client MUST ensure that the DOM nodes corresponding to the records meet the following criteria:
|GUID2||attr||0||GUID1||0||d||M10 10L20 20L20 10Z||N/A||N/A|
Changes to the records can be divided into two categories: commutative and non-commutative edits.
Commutative edits are commutative with all edits and are never "undone" so keeping a history of them is NOT REQUIRED. Edits that add or remove records are commutative.
An edit that changes an existing record is called non-commutative because it may not be commutative with edits that change the same record. Hence these changes may need to be undone so keeping a history of the changes caused by such edits is REQUIRED. The breadth of this required history depends on the role of the entity and on whether the session works through a server component:
|By server||By client|
|Server exists||All non-commutative edits, that have not been undone to records that have not been removed; must store the creator and last modifier of each node (to be included as 'creator' and 'last-modified-by' attributes in <new/> elements sent to joining clients).||Non-commutative edits sent by the client itself. May be removed once a further non-commutative edits to the same record from another entity is received.|
|Server does not exists||---||All non-commutative edits, that have not been undone, to records that have not been removed.|
The server MUST apply commutatative edits to its local copy like a client and pass on the edits without changes.
The server component intercepts and modifies non-commutative edits in order to reduce the history requirements of the clients as indicated above. Once it receives a non-commutative edit, it MUST take the following action depending on whether the version number of the edit is "in-order" (one higher than the current version) or "out-of-order":
A client can add a new node to the document by adding a record with the <new/> element.
|rid||REQUIRED. MUST be a GUID.|
|version||OPTIONAL. MUST be a non-negative integer. Assumed to be 0 if not present.|
|parent||REQUIRED (Except at top level.)|
|primary-weight||OPTIONAL. MUST be a float. Assumed to be 0 if not present.|
|type||REQUIRED. MUST be 'element', 'attr', 'text', 'comment', or 'processinginstruction'|
|ns||OPTIONAL if 'type' is 'element' or 'attr'. Not allowed otherwise.|
|name||REQUIRED if 'type' is 'element' or 'attr'. Not allowed otherwise.|
|chdata||REQUIRED if 'type' is 'attr', 'text', or 'comment'. Not allowed otherwise.|
|pitarget||REQUIRED if 'type' is 'processinginstruction'. Not allowed otherwise.|
|pidata||REQUIRED if 'type' is 'processinginstruction'. Not allowed otherwise.|
|creator||OPTIONAL. MUST be the JID or room nick of the creator of the node.|
|last-modified-by||OPTIONAL. MUST be the JID or room nick of the user who last modified the node.|
To process a <new/> element the client MUST create a new record with the values of the attributes stored in the corresponding fields.
A client can remove any node in the document by removing the corresponding record with the <remove/> element.
|target||REQUIRED and MUST be the record id of the node to be removed.|
A client MUST NOT send a <remove/> element that removes a node that has child nodes without explicitly removing the records of those nodes first.
To processes a <remove/> element the client MUST remove the record specified by the 'target' attribute.
If the node corresponding to the target record has child nodes, the receiver MUST send <remove/> elements for each of them as described above.
The <set/> element is used to modify an existing record.
|target||REQUIRED and MUST be the record id of the node being modified.|
|version||REQUIRED and MUST be the current version of the node incremented by one.|
|ns||OPTIONAL but only allowed if the target record is of type 'element' or 'attr'.|
|name||OPTIONAL but only allowed if the target record is of type 'element' or 'attr'.|
|chdata||OPTIONAL but only allowed if the target node is of type 'attr', 'text', or 'comment'.|
|pitarget||OPTIONAL but only allowed if the target record is of type 'processinginstruction'.|
|pidata||OPTIONAL but only allowed if the target record is of type 'processinginstruction'.|
|replacefrom||replace from position. OPTIONAL but only allowed if 'chdata' and 'replacen' attributes are also included. MUST be a non-negative integer.|
|replacen||replace n characters. OPTIONAL but only allowed if 'chdata' and 'replacefrom' attributes are also included. MUST be a non-negative integer.|
To processes a <set/> element the client MUST follow the following steps:
If the version of of the target record is now equal to the 'version' attribute of the <set/> element, the client MUST store the values of the attributes of the <set/> element as updated values of the corresponding fields in the record. The only exception occurs when 'chdata', 'replacefrom', and 'replacen' are specified: in that case, n characters starting from the f'th character of the existing 'chdata' field MUST be replaced by c, where n, f, and c are the values of the 'replacen', 'replacefrom', and 'chdata' attributes respectively.
Otherwise all fields of the record, except for the 'version' field, must be reverted to version (v - 1), where v is the value of the 'version' attribute of the received <set/> element.
It should be noted that given the MUC specification and the requirement of this protocol to send a connect request message to all room members in order to join an existing session, you effectively can not use the visitor role of MUC with a regular MUC server component. However, the specialized MUC component, if used, MUST accept and respond to the connection requests even if they come from users who do not have voice in the room.
This XEP requires no interaction with the Internet Assigned Numbers Authority (IANA) .
Until this specification advances to a status of Draft, its associated namespaces shall be:
The following namespaces are requested, and are thought to be unique per the XMPP Registrar's requirements:
The ®ISTRAR; shall add the type of "sxe" to the "collaboration" category in its registry of service discovery identities.
The XMPP Registrar shall include "sxe" in its registry of Jingle transport methods. The registry submission is as follows:
The theory behind the synchronization of an individual entity (a record) was put forward by Mats Bengtsson (http://coccinella.sourceforge.net/docs/MemoSyncSVG-XMPP.txt). He also provided other input that helped form this XEP. Thanks to Dmitriy Chervov for his feedback based on implementation experience.
This document in other formats: XML PDF
This XMPP Extension Protocol is copyright © 1999 – 2019 by the XMPP Standards Foundation (XSF).
Permission is hereby granted, free of charge, to any person obtaining a copy of this specification (the "Specification"), to make use of the Specification without restriction, including without limitation the rights to implement the Specification in a software program, deploy the Specification in a network service, and copy, modify, merge, publish, translate, distribute, sublicense, or sell copies of the Specification, and to permit persons to whom the Specification is furnished to do so, subject to the condition that the foregoing copyright notice and this permission notice shall be included in all copies or substantial portions of the Specification. Unless separate permission is granted, modified works that are redistributed shall not contain misleading information regarding the authors, title, number, or publisher of the Specification, and shall not claim endorsement of the modified works by the authors, any organization or project to which the authors belong, or the XMPP Standards Foundation.
## NOTE WELL: This Specification is provided on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. ##
In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall the XMPP Standards Foundation or any author of this Specification be liable for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising from, out of, or in connection with the Specification or the implementation, deployment, or other use of the Specification (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if the XMPP Standards Foundation or such author has been advised of the possibility of such damages.
This XMPP Extension Protocol has been contributed in full conformance with the XSF's Intellectual Property Rights Policy (a copy of which can be found at <https://xmpp.org/about/xsf/ipr-policy> or obtained by writing to XMPP Standards Foundation, P.O. Box 787, Parker, CO 80134 USA).
The Extensible Messaging and Presence Protocol (XMPP) is defined in the XMPP Core (RFC 6120) and XMPP IM (RFC 6121) specifications contributed by the XMPP Standards Foundation to the Internet Standards Process, which is managed by the Internet Engineering Task Force in accordance with RFC 2026. Any protocol defined in this document has been developed outside the Internet Standards Process and is to be understood as an extension to XMPP rather than as an evolution, development, or modification of XMPP itself.
The primary venue for discussion of XMPP Extension Protocols is the <firstname.lastname@example.org> discussion list.
Discussion on other xmpp.org discussion lists might also be appropriate; see <http://xmpp.org/about/discuss.shtml> for a complete list.
Errata can be sent to <email@example.com>.
The following requirements keywords as used in this document are to be interpreted as described in RFC 2119: "MUST", "SHALL", "REQUIRED"; "MUST NOT", "SHALL NOT"; "SHOULD", "RECOMMENDED"; "SHOULD NOT", "NOT RECOMMENDED"; "MAY", "OPTIONAL".
6. The Internet Assigned Numbers Authority (IANA) is the central coordinator for the assignment of unique parameter values for Internet protocols, such as port numbers and URI schemes. For further information, see <http://www.iana.org/>.
7. The XMPP Registrar maintains a list of reserved protocol namespaces as well as registries of parameters used in the context of XMPP extension protocols approved by the XMPP Standards Foundation. For further information, see <https://xmpp.org/registrar/>.
Note: Older versions of this specification might be available at http://xmpp.org/extensions/attic/
Fix use of incorrect namespace in examples
Initial published version.
Updated Jingle namespaces, transport definitions, reason codes, and other syntax; improved feature discovery and session advertisement; updated namespace to be urn:xmpp:sxe:0 for future-compatibility.
Added session signalling via presence.
Wording changes. Changes to how set content/move element conflict is handled.
Initial version of the SXdE proposal after splitting the previous whiteboarding proposal.