# XML Event Format for CloudEvents - Version 1.0.3-wip ## Abstract This format specification for CloudEvents defines how events are expressed in XML documents. The following are related to this specification but have been closed due to inactivity. If someone would like to reopen, and drive to completion, any of these issues please comment in the issue(s). - [Create a PR with some tweaks to the wording about relationship of context attrs and data](https://github.com/cloudevents/spec/issues/1250#top) - [Create an issue for CE xsi type](https://github.com/cloudevents/spec/issues/1238#top) - [XSD - Provide concrete XSD that XML Documents can Validated against](https://github.com/cloudevents/spec/issues/1015#top) - [Named Element 'ExtensionAttributes' of Type any](https://github.com/cloudevents/spec/issues/1014#top) - [add some info about extension attributes](https://github.com/cloudevents/spec/pull/1335) ## Status of this document This document is a working draft. ## Table of Contents 1. [Introduction](#1-introduction) 2. [Attributes](#2-attributes) 3. [Data](#3-data) 4. [Envelope](#4-envelope) 5. [XML Batch Format](#5-xml-batch-format) 6. [Examples](#6-examples) ## 1. Introduction [CloudEvents][ce-spec] is a standardized and protocol-agnostic definition of the structure and metadata description of events. This specification defines how elements defined in the CloudEvents specification are to be represented using [Extensible Markup Language (XML)][xml-spec] elements. * The [Attributes](#2-attributes) section describes the representation and data type mappings for CloudEvents context attributes. * The [Data](#3-data) section defines the container for the data portion of a CloudEvent. * The [Envelope](#4-envelope) section defines an XML element to contain CloudEvent context attributes and data. * The [Batch](#5-xml-batch-format) section describes how multiple CloudEvents can be packaged into a single XML element. ### 1.1. Conformance The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in [RFC2119][rfc2119]. ### 1.2 Approach The XML representation used is deliberately verbose in favor of readability and deterministic processing. Preservation of type information for CloudEvent attributes is supported allowing custom extensions to be communicated without type loss. A schema-less approach has been taken favoring convention over rigid document structure. The namespace `http://cloudevents.io/xmlformat/V1` MUST be used. When namespace prefixes are used a prefix of `ce` is preferred but MUST NOT be expected from an XML document processing perspective. Where an event (or batch of events) is represented as a complete XML document, an XML document preamble SHOULD be included to ensure deterministic processing. XML comments are permitted anywhere within an XML representation of a CloudEvent or CloudEvent batch. Comments MUST be ignored during processing, except for the child element of a `` element containing [XML element data](#33-xml-element-data), where all nodes MUST be preserved. CDATA nodes and regular text nodes MUST be treated interchangeably during processing, except for the child element `` element containing [XML element data](#33-xml-element-data), where all nodes MUST be preserved. XML elements in namespaces other than `http://cloudevents.io/xmlformat/V1`, and XML attributes other than those described in this specification MAY appear within an XML representation of a CloudEvent or CloudEvent batch. These SHOULD be ignored during CloudEvent processing, except for the child element of a `` element containing [XML element data](#33-xml-element-data), where all nodes MUST be preserved. ## 2. Attributes The CloudEvents type system is mapped to a set of CloudEvent specific type designators as follows : | CloudEvents Type | XML Format Type | XML Schema Type | Notes | | :-----------------| :----------------| :--------------- | :---- | | Boolean | ce:boolean | [xs:boolean][xml-primitives] | `true` or `false` | | Integer | ce:integer | [xs:int][xml-primitives] | | | String | ce:string | [xs:string][xml-primitives] | | | Binary | ce:binary | [xs:base64Binary][xml-primitives] | | | URI | ce:uri | [xs:anyURI][xml-primitives] following [RFC 3986][rfc3986]| | | URI-reference | ce:uriRef | [xs:anyURI][xml-primitives] following [RFC 3986][rfc3986] | | | Timestamp | ce:timestamp | [xs:dateTime][xml-primitives] following [RFC 3339][rfc3339] | | Each CloudEvent context attribute MUST be represented as an XML element whose local name exactly matches that of the attribute. See the [envelope](#4-envelope) for special handing of the `specversion` context attribute. Extension context attributes MUST be decorated with the appropriate CloudEvent type format designators using an `xsi:type` XML attribute, this allows them to be exchanged without loss of type information. An XML element representing a core context attribute MAY be decorated with an `xsi:type` XML attribute. If present, this designator MUST match that of the type specified by the [CloudEvent context attributes][ce-attrs]. An XML element representing a context attribute MUST NOT contain any child elements. The text within an XML element representing a context attribute MUST NOT contain any line breaks. When processing the text, the attribute value MUST be parsed without discarding any other whitespace. (For example, ` text ` represents an extension attribute value with leading and trailing whitespace, whereas ` 10 ` is invalid as the textual representation of an Integer attribute never contains whitespace.) No other XML element attributes are expected, if present they MUST be ignored during processing. ``` xml ... AAABBBCCCNNN0000 .. .. my extension value false ``` ## 3. Data The data portion of a CloudEvent follows a similar model to that employed by the [JSON Format specification][json-format]. A `` element MUST be used to encapsulate the payload. An `xsi:type` is used to discrimate the payload type and MUST be present. The `` element MUST NOT occur more than once within an `` element. The following data representations are supported: ### 3.1 Binary Data Binary data MUST be carried in an element with a defined type of `xs:base64Binary` and encoded appropriately. The element MUST NOT contain any child elements. Example: ``` xml ......... ``` ### 3.2 Text Data Text MUST be carried in an element with a defined type of `xs:string`. The element MUST NOT contain any child elements. Example: ``` xml This is text ``` ### 3.3 XML Element Data XML element data MUST be carried in an element with a defined type of `xs:any` with exactly one child XML element (with any mandatory namespace definitions). All XML nodes (including comments and CDATA nodes) within the child XML element MUST be preserved during processing. The `` XML element MUST NOT contain any direct child text nodes with non-whitespace content. There are no restrictions on the content of the child XML element. Example: ``` xml .... ``` ## 4. Envelope Each CloudEvent is wholly represented as an `` XML element that MUST carry the `specversion` as an XML attribute value. Such a representation MUST use the media type `application/cloudevents+xml`. The enveloping element contains: * A set of CloudEvent context attribute XML elements. * An OPTIONAL `` XML element. The `` element MUST NOT contain any direct child text nodes with non-whitespace content. Example _(XML preamble and namespace definitions omitted for brevity)_: ``` xml text/plain 000-1111-2222 urn:uuid:123e4567-e89b-12d3-a456-426614174000 SOME.EVENT.TYPE false Now is the winter of our discount tents... ``` ## 5. XML Batch Format In the _XML Batch Format_ several CloudEvents are batched into a single XML `` element. The element comprises a list of elements in the XML Format. The `` element MUST NOT contain any direct child text nodes with non-whitespace content. The `` element MUST NOT contain any direct child elements in the namespace `http://cloudevents.io/xmlformat/V1` except `` elements. An XML Batch of CloudEvents MUST use the media type `application/cloudevents-batch+xml`. Example _(XML preamble and namespace definitions omitted for brevity)_: ```xml .... .... .... ``` ## 6. Examples ### 6.1 CloudEvent with PNG image data ```xml image/png 000-1111-2222 urn:uuid:123e4567-e89b-12d3-a456-426614174000 SOME.EVENT.TYPE ... Base64 encoded data... ``` ### 6.2 CloudEvent with JSON event data ```xml application/json 000-1111-2222 urn:uuid:123e4567-e89b-12d3-a456-426614174000 SOME.EVENT.TYPE { "salutation": "Good Morning", "text": "hello world" } ``` ### 6.3 CloudEvent with XML event data #### 6.3.1 Locally namespaced event data ```xml application/xml 000-1111-2222 urn:uuid:123e4567-e89b-12d3-a456-426614174000 SOME.EVENT.TYPE 51.509865 -0.118092 ``` #### 6.3.2 Explicit namespacing ```xml 2020-03-19T12:54:00-07:00 application/xml 000-1111-2222 urn:uuid:123e4567-e89b-12d3-a456-426614174000 SOME.EVENT.TYPE 51.509865 -0.118092 ``` #### 6.3.3 ISO 20022 Usage Example [ISO 20022][iso-20022] is an XML based messaging standard used in the financial industry; this is a non-normative example. ```xml application/xml 000-1111-2222 urn:uuid:123e4567-e89b-12d3-a456-426614174000 com.mybank.pain.001.001.03 ABC/060928/CCT001 2022-02-22T14:07:00 3 2400.56 Cobelfac 0468651441 KBO-BCE ABC/4560/2008-09-25 TRF false ``` #### 6.3.4 Batch Example ```xml image/png 000-1111-2222 urn:uuid:123e4567-e89b-12d3-a456-426614174000 SOME.EVENT.TYPE ... Base64 encoded data... image/png 000-1111-3333 urn:uuid:123e4567-e89b-12d3-a456-426614174000 SOME.EVENT.TYPE ... Base64 encoded data... ..... ``` [ce-spec]: ../spec.md [ce-types]: ../spec.md#type-system [ce-attrs]: ../spec.md#context-attributes [xml-format]: ./xml-format.md [json-format]: ../formats/json-format.md [xml-spec]: https://www.w3.org/TR/2008/REC-xml-20081126/ [xml-primitives]: https://www.w3.org/TR/xmlschema-2/#built-in-primitive-datatypes [rfc2119]: https://tools.ietf.org/html/rfc2119 [rfc3339]: https://www.ietf.org/rfc/rfc3339.txt [rfc3986]: https://tools.ietf.org/html/rfc3986 [iso-20022]: https://www.iso20022.org