除了像销售订单这种显而易见的以数据为中心的文档之外,许多以文本为主的(prose- rich)文档也可以是以数据为中心的.例如,amazon.com用来显示书籍信息的一个页面.尽管页面上大部分内容都是文本,这些文本的结构是非常规则的,许多都与其它书籍的描述相同,每个页面特有的文本并不很多.这样,就可以从数据库中取出书籍的相关资料,转换为简单的.以数据为中心的xml文档,再用xsl样式表生成页面.一般来说,那些用数据库中的数据填充模板,动态生成html文件的网站都可以转而使用一系列以数据为中心的xml文档与xsl样式表.
<flightinfo> <airline>abc airways</airline> provides <count>three</count> non-stop flights daily from <origin>dallas</origin> to <destination>fort worth</destination>. departure times are <departure>09:15</departure>, <departure>11:15</departure>, and <departure>13:15</departure>. arrival times are minutes later. </flightinfo>从下面的xml文件与一个简单的样式表中创建这个文档: 【程序编程相关:Tomcat4/5连接池的设置及简单应用】
例如,下面是个描述航班信息的文档: 【推荐阅读:.NET 框架中的 XML:在 .NET】
以文档为中心的文档通常是供人消费的.例如书籍.email.广告以及几乎所有人工写成的xhtml文件.其特性为结构不太或根本不规则.数据粒度大(larger grained data)(最小的独立数据单位可能存在于包含混合内容的元素甚至整个文档本身),混合内容多.同级元素或pcdata出现的次序一般来说总是非常重要的. 【扩展信息:非常小的shell: 指定行号,插入文本】
<flights> <airline>abc airways</airline> <origin>dallas</origin> <destination>fort worth</destination> <flight> <departure>09:15</departure> <arrival>09:16</arrival> </flight> <flight> <departure>11:15</departure> <arrival>11:16</arrival> </flight> <flight> <departure>13:15</departure> <arrival>13:16</arrival> </flight> </flights>4.2 以文档为中心的文档 (document-centric documents)
以文档为中心的文档通常是以xml手工写成,或从其他格式(如rtf, pdf, sgml)转换到xml,与以数据为中心的文档不同,它们的来源通常不是数据库.(将数据插入到模板而得到的文档是以数据为中心的;更多信息请看4.1节末尾部分).将各种格式转换为xml的软件信息,请参阅xml软件相关链接.
例如,下面这个产品说明是以文档为中心的:
<product> <intro> the <productname>turkey wrench</productname> from <developer>full fabrication labs, inc.</developer> is <summary>like a monkey wrench, but not as big.</summary> </intro> <description> <para>the turkey wrench, which comes in <i>both right- and left- handed versions (skyhook optional)</i>, is made of the <b>finest stainless steel</b>. the readi-grip rubberized handle quickly adapts to your hands, even in the greasiest situations. adjustment is possible through a variety of custom dials.</para> <para>you can:</para> <list> <item><link url="order.html">order your own turkey wrench</link></item> <item><link url="wrenches.htm">read more about wrenches</link></item> <item><link url="catalog.zip">download the catalog</link></item> </list> <para>the turkey wrench costs <b>just $19.99</b> and, if you order now, comes with a <b>hand-crafted shrimp hammer</b> as a bonus gift.</para> </description> </product>4.3 数据.文档与数据库(data, documents, and databases)
在现实当中,以数据为中心与以文档为中心的文档之间的差别不一定很明显.例如,另一种以数据为中心的文档比如发票,可能含有大粒度的.结构不规则的数据比如零件说明;另一种以文档文中心的文件如用户手册,可能包含细粒度的结构规则的数据(通常为元数据)比如作者与修订日期.... 下一页