<?xml version="1.0"?>
<!DOCTYPE rfc SYSTEM "rfc2629.dtd">

<?rfc toc="yes"?>

<rfc ipr="full2026">

	<front>
		<title>XML Streams</title>

		<author initials="J." surname="Miller" fullname="Jeremie Miller">
			<organization>The Jabber.org Project</organization>
			<address>
				<postal>
					<street>414 DeLong St.</street>
					<city>Cascade</city> <region>IA</region>
					<code>52033</code>
					<country>US</country>
				</postal>
				<phone>319-852-3464</phone>
				<email>jeremie@jabber.org</email>
			</address>
		</author>

		<date month="June" year="2000"/>
		<area>Internet</area>

		<abstract><t>
			This memo describes a simple transport layer to contiguously move <xref target="XML">XML</xref> formatted data structures in
			real-time bidirectionally between applications.
		</t></abstract>

	</front>

	<middle>

		<section title="Introduction">
			<t>
				XML Streams are a solution for a specific problem within Jabber: continuously transferring
				dynamically generated <xref target="XML">XML</xref> data bidirectionally over a single TCP socket.  They have been designed and implemented to solve
				that single problem and reduce the complexity of the solution at an absolute minimum.
			</t>
			<section title="Goals">
				<t>The goals of the protocol described in this memo are as follows:
					<list style="bullet">
						<t>Create a stateful communication channel between applications.</t>
						<t>Transfer dynamically generated XML formatted data bi-directionaly over the channel.</t>
						<t>Optimize for longevity of the channel.</t>
						<t>Optimize for time sensitive data.</t>
						<t>Reduce implementation requirements for the originating application.</t>
					</list>
				</t>
			</section>
			<section title="Terms">
				<t>The following terms will be used in this memo:
					<list style="bullet">
						<t>SOCKET: Standard TCP/IP network socket</t>
						<t>TRANSPORT LAYER: Carrier protocol over a SOCKET (examples: HTTP/FTP)</t>
						<t>STREAM: XML based TRANSPORT LAYER as defined in this document</t>
						<t>APPLICATION: Software utilizing a STREAM</t>
						<t>DATA: XML formatted elements within a STREAM</t>
					</list>
				</t>
			</section>
			<section title="Synopsis">
				<t>
					The solution presented in this memo is very simple. Use SOCKET and a TRANSPORT LAYER which is a normal XML
					Document. The SOCKET and XML Document are directly associated, when the SOCKET opens or closes so does
					the XML Document. Essentially, open a SOCKET, exchange an XML Document, and close the SOCKET. All data
					on the SOCKET is a single XML Document.
				</t>
			</section>
		</section>

		<section title="Connecting">
			<section title="Creating SOCKET">
				<t>
					The APPLICATION opens a standard SOCKET or listens for incoming SOCKETs. The APPLICATION may choose any
					appropriate port for the SOCKETs.
				</t>
			</section>
		</section>

		<section title="XML Document">
			<t>
				The entire data stream across the SOCKET is a single XML Document. The <xref target="XML">XML 1.0 Specification</xref>
				fully applies to this data stream, there are no exceptions or alterations. <xref target="namespaces">XML Namespaces</xref> are used to seperate the required
				STREAM information from the DATA carried by the STREAM.
			</t>
			<section title="The stream Namespace">
				<t>
					The "stream" <xref target="namespaces">namespace</xref> defines the valid root element and attributes that are used to
					open a STREAM between the APPLICATIONs.
				</t>
				<section title="Attributes">
					<list style="bullet">
						<t>to - The to="" attribute is analogous to an HTTP Host: header, and contains a valid DNS host address.
							It can be used by the receiving APPLICATION to determine the target virtual name on multihosted IPs.
							This attribute is required to be sent by the APPLICATION opening the STREAM.</t>
						<t>from - The from="" attribute contains a valid DNS host address that should resolve to source SOCKET IP
							address. An APPLICATION may require this attribute and require that it resolves to the source SOCKET IP
							address. This attribute is also required to be sent by the receiving APPLICATION in response to a newly opened
							STREAM to identify itself.</t>
						<t>id - The id="" attribute is a unique idenitifer for this STREAM.  It is optional and it's use is specific to the APPLICATION.</t>
					</list>
				</section>
				<section title="Default Namespace">
					<t>The default Namespace must be explicitly stated within the root tag. This Namespace identifies all of the DATA
					within the STREAM.</t>
				</section>
				<section title="Root Element">
					<figure>
						<preamble>A simple example of a valid Root Element for a STREAM:</preamble>
						<artwork><![CDATA[
<stream:stream
  to="host.foo.org"
  from="host.bar.org"
  xmlns="http://foo/namespace"
  xmlns:stream="http://www.ietf.org/internet-drafts/draft-miller-xmlstreams-00.txt">
						]]></artwork>
					</figure>
					<t>
						The stream:stream sets the current namespace to "stream" which includes the to and from attributes.
						The xmlns="" attribute sets the default namespace to http://foo/namespace which applies to all children.
					</t>
					<figure>
						<preamble>A larger example including multiple namespaces:</preamble>
						<artwork><![CDATA[
<stream:stream
  to="host.foo.org"
  from="host.bar.org"
  xmlns="http://store.com/billing-schema"
  xmlns:edi="http://ecommerce.org/schema"
  xmlns:books="urn:loc.gov:books"
  xmlns:stream="http://www.ietf.org/internet-drafts/draft-miller-xmlstreams-00.txt">
  						]]></artwork>
					</figure>
				</section>
				<section title="DATA">
					<t>
						All of the DATA within the STREAM must be well-formed XML as would be expected in any normal XML Document.
						All of this DATA is application specific and not of concern to the STREAM. The DATA can be in any stated
						namespace or in the default namespace.
					</t>
				</section>
				<section title="Parsing">
					<t>
						The XML must be parsed continually as data is available on the SOCKET.  This can be accomplished with a non-buffered <!-- <xref target="SAX">SAX</xref> --> parser or
						chunk parser such as <!-- <xref target="Expat">Expat</xref> -->.  Often it is adventagous to the APPLICATION to break the DATA by top-level elements
						which are made available individually via the <!-- <xref target="DOM">DOM</xref> --> or a similiar API.
</t>
				</section>
			</section>
		</section>

		<section title="Closing the Connection">
			<section title="STREAM Close">
				<t>
					Sending a closing &lt;/stream:stream> XML tag would be followed immediately by a SOCKET close on both sides of the
					STREAM.
				</t>
			</section>
			<section title="SOCKET Close">
				<t>A standard SOCKET close implies a &lt;/stream:stream> and would close the STREAM.</t>
			</section>
		</section>
			
		<section title="Errors">
			<section title="XML Processing Errors">
				<t>
					If the STREAM is found to not be well-formed XML at any point in the processing, the APPLICATION is
					required to appropriately close the STREAM. The APPLICATION may optionally send an error in the namespace 
					appropriate for that conversation.
				</t>
			</section>
			<section title="Network Errors">
				<t>
					If there is a network error, the SOCKET and STREAM are no longer valid.
				</t>
			</section>
			<section title="Application Errors">
				<t>
					APPLICATION errors should be handled appropriately by the APPLICATION in its namespace. If the STREAM needs to be
					closed because of an error, the APPLICATION should STREAM close.
				</t>
			</section>
			<section title="STREAM Error">
				<t>
					A convenience error element is in the stream namespace. This error element only contains CDATA and
					may be used by the APPLICATION as a way to send a STREAM level error message. It would be
					appropriate to use this element when the namespace negotiation between APPLICATIONs failed and
					there is no common namespace to express an error in.
				</t>
				<figure>
					<preamble>Simple STREAM Error Example:</preamble>
					<artwork><![CDATA[
<stream:error>Invalid Namespace</stream:error>
					]]></artwork>
				</figure>
			</section>
		</section>

		<section title="Examples">
			<t>
				Fictional Namespaces: The namespaces used in the following examples are fictional (except
				the stream namespace).
			</t>
			<figure>
				<preamble>Simple example of a full STREAM:</preamble>
				<artwork><![CDATA[
<?xml version="1.0"?>
<stream:stream
  to="host.foo.org"
  from="host.bar.org"
  xmlns="world:hello"
  xmlns:stream="http://etherx.jabber.org/streams">
  <hello>world</hello>
</stream:stream>
				]]></artwork>
			</figure>
			<figure>
				<preamble>Another example STREAM utilizing more namespaces:</preamble>
				<artwork><![CDATA[
<?xml version="1.0"?>
<stream:stream
  to="server.com"
  from="host.isp.net"
  xmlns="http://isp.net/billing-schema"
  xmlns:edi="http://ecommerce.org/edi"
  xmlns:stream="http://etherx.jabber.org/streams">
  <transaction customer="jean@isp.net"><edi:ticket id="A532F910"/></transaction>
  <transaction customer="amy@isp.net"><edi:ticket id="DD642F18"/></transaction>
  <transaction customer="jerry@isp.net"><edi:ticket id="655387E2"/></transaction>
</stream:stream>
				]]></artwork>
			</figure>
		</section>

	</middle>

	<back>

		<references>

			<reference anchor="XML" target="http://www.w3.org/TR/1998/REC-xml-19980210">
				<front>
					<title>Extensible Markup Language (XML) 1.0</title>
					<author>
						<organization abbrev="W3C">World Wide Web Consortium</organization>
					</author>
					<date month="February" year="1998"/>
				</front>
				<seriesInfo name="W3C" value="xml"/>
			</reference>
		
			<reference anchor="namespaces" target="http://www.w3.org/TR/1999/REC-xml-names-19990114/">
				<front>
					<title>Namespaces in XML</title>
					<author>
						<organization abbrev="W3C">World Wide Web Consortium</organization>
					</author>
					<date month="January" year="1999"/>
				</front>
				<seriesInfo name="W3C" value="xml-names"/>
			</reference>

		</references>

		<section title="XML Streams DTD">
			<figure>
				<artwork><![CDATA[
<!ELEMENT stream (error?)>
<!ATTLIST stream
  to              CDATA       #REQUIRED
  from            CDATA       #IMPLIED
  id              CDATA       #IMPLIED
  xmlns           CDATA       #REQUIRED
  xmlns:stream    CDATA       #REQUIRED 'http://www.ietf.org/internet-drafts/draft-miller-xmlstreams-00.txt'
  >
<!ELEMENT error (PCDATA)>
				]]></artwork>
			</figure>
		</section>

	</back>

</rfc>
