xml – 在自定义媒体类型中创建超媒体链接

我目前正在为RESTful api创建一组自定义媒体类型(例如application / vnd.mycompany.foo xml),我试图找出两种不同的暴露超媒体链接方式的优缺点.

如果我首先考虑其他媒体类型可能最好的起点是HTML. Html允许我创建链接,例如:

<image src="http://example.com/image.gif"/>
<a href="http://example.com/page.html"/>
<form action="http://example.com/page.html"/>
<link rel="stylesheet" type="text/css" href="theme.css" />

这里有趣的是,在某些情况下,某些特定标签具有url属性,然后是使用rel属性定义关系的通用链接标记.

在Atompub中,还有一些资源链接在一起的方式

<collection href="http://example.org/blog/main" >
         <atom:title>My Blog Entries</atom:title>
         <categories href="http://example.com/cats/forMain.cats" />
</collection>

<atom:category scheme="http://example.org/extra-cats/" term="joke" />
<atom:entry>
   <link rel="edit" href="http://example.org/edit/first-post.atom"/>
</atom:entry>

我要问的问题是,何时使用具有关系的链接元素更有意义,何时将属性添加到现有元素更有意义.

例如Atompub链接可能已经完成

<collection>
      <link rel="source" href="http://example.org/blog/main"/>
         <atom:title>My Blog Entries</atom:title>
         <categories>
                <link rel="source" href="http://example.com/cats/forMain.cats"/>
         </categories>
</collection>

<atom:category term="joke">
     <link rel="scheme" href="http://example.org/extra-cats/"/>
<atom:category>
<atom:entry edit="http://example.org/edit/first-post.atom"/>

通常情况下,在写这个问题时,答案似乎显而易见.必需的链接作为属性公开,可选的链接作为元素公开.但是,我非常有兴趣听取其他人对他们认为如何表示链接的看法.

我对 XHTML 2的喜欢是 every element could have a link.

为什么不利用XLink来实现相同的功能呢?那样,没必要选择.

相关文章

php输出xml格式字符串
J2ME Mobile 3D入门教程系列文章之一
XML轻松学习手册
XML入门的常见问题(一)
XML入门的常见问题(三)
XML轻松学习手册(2)XML概念