📄 x557.htm
字号:
<HTML
><HEAD
><TITLE
>Payload Carrier</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.64
"><LINK
REL="HOME"
TITLE="Programming Jabber"
HREF="book1.htm"><LINK
REL="UP"
TITLE="Inside Jabber"
HREF="c445.htm"><LINK
REL="PREVIOUS"
TITLE="Messaging"
HREF="x524.htm"><LINK
REL="NEXT"
TITLE="Request/Response"
HREF="x624.htm"></HEAD
><BODY
CLASS="SECT1"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>Programming Jabber</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="x524.htm"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
>Chapter 2. Inside Jabber</TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="x624.htm"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="SECT1"
><H1
CLASS="SECT1"
><A
NAME="JABTDG-CH-2-SECT-2.4"
>Payload Carrier</A
></H1
><P
>Earlier in this chapter we saw how a basic message was embellished with
a structured and parseable 'attachment' in the form of a
<TT
CLASS="LITERAL"
>jabber:x:oob</TT
> qualified <TT
CLASS="LITERAL"
><x/></TT
>
tag, and its child tags:</P
><P
><PRE
CLASS="SCREEN"
><x xmlns='jabber:x:oob'>
<url>http://www.megacorp.co.uk/earnings3q.html</url>
<desc>Third Quarter Earnings for Megacorp</desc>
</x></PRE
></P
><P
>How does this actually work in practice? Well, partly by requirement, partly
by convention. </P
><P
></P
><UL
><LI
><P
>All three of the elements <TT
CLASS="LITERAL"
><message/></TT
>,
<TT
CLASS="LITERAL"
><iq/></TT
> and <TT
CLASS="LITERAL"
><presence/></TT
>
can carry these attachments.</P
></LI
><LI
><P
>These attachments usually server one of two purposes</P
><P
></P
><UL
><LI
><P
>to bring primary (or secondary) meaning to the element that contains it</P
></LI
><LI
><P
>to act as the driving force behind the element, such as that the element
really only exists to carry the attachment</P
></LI
></UL
><P
>This distinction is rather subtle, so let's look at a couple of examples.</P
><DIV
CLASS="EXAMPLE"
><A
NAME="JABTDG-CH-2-EX-2"
></A
><P
><B
>Example 2-2. A <TT
CLASS="LITERAL"
>jabber:x:delay</TT
> extension adds meaning to a <TT
CLASS="LITERAL"
><presence/></TT
> element</B
></P
><P
><PRE
CLASS="SCREEN"
><presence from='jim@company-a.com/home' to='john@company-b.com'>
<show>chat</show>
<status>having a break from work</status>
<priority>1</priority>
<x xmlns='jabber:x:delay' from='jim@company-a.com/home'
stamp='20010611T13:13:04'/>
</presence></PRE
></P
></DIV
><P
><A
HREF="x557.htm#JABTDG-CH-2-EX-2"
>Example 2-2</A
>
shows an attachment in the <TT
CLASS="LITERAL"
>jabber:x:delay</TT
>
namespace. This works like a timestamp, and in this context indicates when
that presence element appeared, in other words, from what time Jim started
on his break.</P
><DIV
CLASS="EXAMPLE"
><A
NAME="JABTDG-CH-2-EX-3"
></A
><P
><B
>Example 2-3. A <TT
CLASS="LITERAL"
>jabber:x:oob</TT
> extension is the heart of a <TT
CLASS="LITERAL"
><message/></TT
> element</B
></P
><P
><PRE
CLASS="SCREEN"
><message type='headline' from='jabbercentral@news.company-b.com'
to='john@company-b.com'>
<x xmlns='jabber:x:oob'>
<url>http://www.jabbercentral.com/news/view.php?news_id='989358658</url>
<desc>
Tomorrow, May 9th, a meeting regarding the Jabber Foundation
will be held.
</desc>
</x>
</message></PRE
></P
></DIV
><P
><A
HREF="x557.htm#JABTDG-CH-2-EX-3"
>Example 2-3</A
>
shows us a message element containing a URL attachment. In this
case the element serves to carry the URL attachment; there is not really
any other purpose to it. Delivering the
<TT
CLASS="LITERAL"
><message type='headline'/></TT
>
carrier without the payload wouldn't make much sense.</P
></LI
><LI
><P
>The outermost tag of each attachment, by convention, is either
<TT
CLASS="LITERAL"
><x/></TT
> or <TT
CLASS="LITERAL"
><query/></TT
>
although they can be any valid XML tag name. The Jabber namespaces that
are used to qualify these <TT
CLASS="LITERAL"
><x/></TT
> and
<TT
CLASS="LITERAL"
><query/></TT
> attachments follow a convention,
beginning</P
><P
><TT
CLASS="LITERAL"
>jabber:x:</TT
></P
><P
>for those qualifying the <TT
CLASS="LITERAL"
><x/></TT
> attachments, and</P
><P
><TT
CLASS="LITERAL"
>jabber:iq:</TT
></P
><P
>for those qualifying the <TT
CLASS="LITERAL"
><query/></TT
> attachments.</P
><P
><TT
CLASS="LITERAL"
><x/></TT
> is used as a generic extension mechanism
to add information to any of the Jabber elements, and
<TT
CLASS="LITERAL"
><query/></TT
> is used to extend the
<TT
CLASS="LITERAL"
><iq/></TT
> element. </P
></LI
></UL
><P
><A
HREF="c3612.htm"
>Chapter 5</A
>
lists the standard namespaces used in Jabber to qualify the
<TT
CLASS="LITERAL"
><x/></TT
> and <TT
CLASS="LITERAL"
><query/></TT
>
attachments. But we're not restricted to just those namespaces - we're
free to build our own attachments qualified by our own namespaces, if
we think that what we want to achieve isn't covered by anything 'out of
the box'. In this situation, there are two things to note:</P
><P
></P
><UL
><LI
><P
>the namespaces cannot begin 'jabber:'</P
></LI
><LI
><P
>the receiving recipient of the extended element must be able
to appropriately interpret the attachments (!)</P
></LI
></UL
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="x524.htm"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="book1.htm"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="x624.htm"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>Messaging</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="c445.htm"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>Request/Response</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -