guidelines.html 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  2. "http://www.w3.org/TR/html4/loose.dtd">
  3. <html>
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html">
  6. <style type="text/css"></style>
  7. <!--
  8. TD {font-family: Verdana,Arial,Helvetica}
  9. BODY {font-family: Verdana,Arial,Helvetica; margin-top: 2em; margin-left: 0em; margin-right: 0em}
  10. H1 {font-family: Verdana,Arial,Helvetica}
  11. H2 {font-family: Verdana,Arial,Helvetica}
  12. H3 {font-family: Verdana,Arial,Helvetica}
  13. A:link, A:visited, A:active { text-decoration: underline }
  14. </style>
  15. -->
  16. <title>XML resources publication guidelines</title>
  17. </head>
  18. <body bgcolor="#fffacd" text="#000000">
  19. <h1 align="center">XML resources publication guidelines</h1>
  20. <p></p>
  21. <p>The goal of this document is to provide a set of guidelines and tips
  22. helping the publication and deployment of <a
  23. href="http://www.w3.org/XML/">XML</a> resources for the <a
  24. href="http://www.gnome.org/">GNOME project</a>. However it is not tied to
  25. GNOME and might be helpful more generally. I welcome <a
  26. href="mailto:veillard@redhat.com">feedback</a> on this document.</p>
  27. <p>The intended audience is the software developers who started using XML
  28. for some of the resources of their project, as a storage format, for data
  29. exchange, checking or transformations. There have been an increasing number
  30. of new XML formats defined, but not all steps have been taken, possibly because of
  31. lack of documentation, to truly gain all the benefits of the use of XML.
  32. These guidelines hope to improve the matter and provide a better overview of
  33. the overall XML processing and associated steps needed to deploy it
  34. successfully:</p>
  35. <p>Table of contents:</p>
  36. <ol>
  37. <li><a href="#Design">Design guidelines</a></li>
  38. <li><a href="#Canonical">Canonical URL</a></li>
  39. <li><a href="#Catalog">Catalog setup</a></li>
  40. <li><a href="#Package">Package integration</a></li>
  41. </ol>
  42. <h2><a name="Design">Design guidelines</a></h2>
  43. <p>This part intends to focus on the format itself of XML. It may arrive
  44. a bit too late since the structure of the document may already be cast in
  45. existing and deployed code. Still, here are a few rules which might be helpful
  46. when designing a new XML vocabulary or making the revision of an existing
  47. format:</p>
  48. <h3>Reuse existing formats:</h3>
  49. <p>This may sounds a bit simplistic, but before designing your own format,
  50. try to lookup existing XML vocabularies on similar data. Ideally this allows
  51. you to reuse them, in which case a lot of the existing tools like DTD, schemas
  52. and stylesheets may already be available. If you are looking at a
  53. documentation format, <a href="http://www.docbook.org/">DocBook</a> should
  54. handle your needs. If reuse is not possible because some semantic or use case
  55. aspects are too different this will be helpful avoiding design errors like
  56. targeting the vocabulary to the wrong abstraction level. In this format
  57. design phase try to be synthetic and be sure to express the real content of
  58. your data and use the XML structure to express the semantic and context of
  59. those data.</p>
  60. <h3>DTD rules:</h3>
  61. <p>Building a DTD (Document Type Definition) or a Schema describing the
  62. structure allowed by instances is the core of the design process of the
  63. vocabulary. Here are a few tips:</p>
  64. <ul>
  65. <li>use significant words for the element and attributes names.</li>
  66. <li>do not use attributes for general textual content, attributes
  67. will be modified by the parser before reaching the application,
  68. spaces and line informations will be modified.</li>
  69. <li>use single elements for every string that might be subject to
  70. localization. The canonical way to localize XML content is to use
  71. siblings element carrying different xml:lang attributes like in the
  72. following:
  73. <pre>&lt;welcome&gt;
  74. &lt;msg xml:lang="en"&gt;hello&lt;/msg&gt;
  75. &lt;msg xml:lang="fr"&gt;bonjour&lt;/msg&gt;
  76. &lt;/welcome&gt;</pre>
  77. </li>
  78. <li>use attributes to refine the content of an element but avoid them for
  79. more complex tasks, attribute parsing is not cheaper than an element and
  80. it is far easier to make an element content more complex while attribute
  81. will have to remain very simple.</li>
  82. </ul>
  83. <h3>Versioning:</h3>
  84. <p>As part of the design, make sure the structure you define will be usable
  85. for future extension that you may not consider for the current version. There
  86. are two parts to this:</p>
  87. <ul>
  88. <li>Make sure the instance contains a version number which will allow to
  89. make backward compatibility easy. Something as simple as having a
  90. <code>version="1.0"</code> on the root document of the instance is
  91. sufficient.</li>
  92. <li>While designing the code doing the analysis of the data provided by the
  93. XML parser, make sure you can work with unknown versions, generate a UI
  94. warning and process only the tags recognized by your version but keep in
  95. mind that you should not break on unknown elements if the version
  96. attribute was not in the recognized set.</li>
  97. </ul>
  98. <h3>Other design parts:</h3>
  99. <p>While defining you vocabulary, try to think in term of other usage of your
  100. data, for example how using XSLT stylesheets could be used to make an HTML
  101. view of your data, or to convert it into a different format. Checking XML
  102. Schemas and looking at defining an XML Schema with a more complete
  103. validation and datatyping of your data structures is important, this helps
  104. avoiding some mistakes in the design phase.</p>
  105. <h3>Namespace:</h3>
  106. <p>If you expect your XML vocabulary to be used or recognized outside of your
  107. application (for example binding a specific processing from a graphic shell
  108. like Nautilus to an instance of your data) then you should really define an <a
  109. href="http://www.w3.org/TR/REC-xml-names/">XML namespace</a> for your
  110. vocabulary. A namespace name is an URL (absolute URI more precisely). It is
  111. generally recommended to anchor it as an HTTP resource to a server associated
  112. with the software project. See the next section about this. In practice this
  113. will mean that XML parsers will not handle your element names as-is but as a
  114. couple based on the namespace name and the element name. This allows it to
  115. recognize and disambiguate processing. Unicity of the namespace name can be
  116. for the most part guaranteed by the use of the DNS registry. Namespace can
  117. also be used to carry versioning information like:</p>
  118. <p><code>"http://www.gnome.org/project/projectname/1.0/"</code></p>
  119. <p>An easy way to use them is to make them the default namespace on the
  120. root element of the XML instance like:</p>
  121. <pre>&lt;structure xmlns="http://www.gnome.org/project/projectname/1.0/"&gt;
  122. &lt;data&gt;
  123. ...
  124. &lt;/data&gt;
  125. &lt;/structure&gt;</pre>
  126. <p>In that document, structure and all descendant elements like data are in
  127. the given namespace.</p>
  128. <h2><a name="Canonical">Canonical URL</a></h2>
  129. <p>As seen in the previous namespace section, while XML processing is not
  130. tied to the Web there is a natural synergy between both. XML was designed to
  131. be available on the Web, and keeping the infrastructure that way helps
  132. deploying the XML resources. The core of this issue is the notion of
  133. "Canonical URL" of an XML resource. The resource can be an XML document, a
  134. DTD, a stylesheet, a schema, or even non-XML data associated with an XML
  135. resource, the canonical URL is the URL where the "master" copy of that
  136. resource is expected to be present on the Web. Usually when processing XML a
  137. copy of the resource will be present on the local disk, maybe in
  138. /usr/share/xml or /usr/share/sgml maybe in /opt or even on C:\projectname\
  139. (horror !). The key point is that the way to name that resource should be
  140. independent of the actual place where it resides on disk if it is available,
  141. and the fact that the processing will still work if there is no local copy
  142. (and that the machine where the processing is connected to the Internet).</p>
  143. <p>What this really means is that one should never use the local name of a
  144. resource to reference it but always use the canonical URL. For example in a
  145. DocBook instance the following should not be used:</p>
  146. <pre>&lt;!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"<br>
  147. "/usr/share/xml/docbook/4.2/docbookx.dtd"&gt;</pre>
  148. <p>But always reference the canonical URL for the DTD:</p>
  149. <pre>&lt;!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"<br>
  150. "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd"&gt; </pre>
  151. <p>Similarly, the document instance may reference the <a
  152. href="http://www.w3.org/TR/xslt">XSLT</a> stylesheets needed to process it to
  153. generate HTML, and the canonical URL should be used:</p>
  154. <pre>&lt;?xml-stylesheet
  155. href="http://docbook.sourceforge.net/release/xsl/current/html/docbook.xsl"
  156. type="text/xsl"?&gt;</pre>
  157. <p>Defining the canonical URL for the resources needed should obey a few
  158. simple rules similar to those used to design namespace names:</p>
  159. <ul>
  160. <li>use a DNS name you know is associated to the project and will be
  161. available on the long term</li>
  162. <li>within that server space, reserve the right to the subtree where you
  163. intend to keep those data</li>
  164. <li>version the URL so that multiple concurrent versions of the resources
  165. can be hosted simultaneously</li>
  166. </ul>
  167. <h2><a name="Catalog">Catalog setup</a></h2>
  168. <h3>How catalogs work:</h3>
  169. <p>The catalogs are the technical mechanism which allow the XML processing
  170. tools to use a local copy of the resources if it is available even if the
  171. instance document references the canonical URL. <a
  172. href="http://www.oasis-open.org/committees/entity/">XML Catalogs</a> are
  173. anchored in the root catalog (usually <code>/etc/xml/catalog</code> or
  174. defined by the user). They are a tree of XML documents defining the mappings
  175. between the canonical naming space and the local installed ones, this can be
  176. seen as a static cache structure.</p>
  177. <p>When the XML processor is asked to process a resource it will
  178. automatically test for a locally available version in the catalog, starting
  179. from the root catalog, and possibly fetching sub-catalog resources until it
  180. finds that the catalog has that resource or not. If not the default
  181. processing of fetching the resource from the Web is done, allowing in most
  182. case to recover from a catalog miss. The key point is that the document
  183. instances are totally independent of the availability of a catalog or from
  184. the actual place where the local resource they reference may be installed.
  185. This greatly improves the management of the documents in the long run, making
  186. them independent of the platform or toolchain used to process them. The
  187. figure below tries to express that mechanism:<img src="catalog.gif"
  188. alt="Picture describing the catalog "></p>
  189. <h3>Usual catalog setup:</h3>
  190. <p>Usually catalogs for a project are setup as a 2 level hierarchical cache,
  191. the root catalog containing only "delegates" indicating a separate subcatalog
  192. dedicated to the project. The goal is to keep the root catalog clean and
  193. simplify the maintenance of the catalog by using separate catalogs per
  194. project. For example when creating a catalog for the <a
  195. href="http://www.w3.org/TR/xhtml1">XHTML1</a> DTDs, only 3 items are added to
  196. the root catalog:</p>
  197. <pre> &lt;delegatePublic publicIdStartString="-//W3C//DTD XHTML 1.0"
  198. catalog="file:///usr/share/sgml/xhtml1/xmlcatalog"/&gt;
  199. &lt;delegateSystem systemIdStartString="http://www.w3.org/TR/xhtml1/DTD"
  200. catalog="file:///usr/share/sgml/xhtml1/xmlcatalog"/&gt;
  201. &lt;delegateURI uriStartString="http://www.w3.org/TR/xhtml1/DTD"
  202. catalog="file:///usr/share/sgml/xhtml1/xmlcatalog"/&gt;</pre>
  203. <p>They are all "delegates" meaning that if the catalog system is asked to
  204. resolve a reference corresponding to them, it has to lookup a sub catalog.
  205. Here the subcatalog was installed as
  206. <code>/usr/share/sgml/xhtml1/xmlcatalog</code> in the local tree. That
  207. decision is left to the sysadmin or the packager for that system and may
  208. obey different rules, but the actual place on the filesystem (or on a
  209. resource cache on the local network) will not influence the processing as
  210. long as it is available. The first rule indicate that if the reference uses a
  211. PUBLIC identifier beginning with the</p>
  212. <p><code>"-//W3C//DTD XHTML 1.0"</code></p>
  213. <p>substring, then the catalog lookup should be limited to the specific given
  214. lookup catalog. Similarly the second and third entries indicate those
  215. delegation rules for SYSTEM, DOCTYPE or normal URI references when the URL
  216. starts with the <code>"http://www.w3.org/TR/xhtml1/DTD"</code> substring
  217. which indicates the location on the W3C server where the XHTML1 resources are
  218. stored. Those are the beginning of all Canonical URLs for XHTML1 resources.
  219. Those three rules are sufficient in practice to capture all references to XHTML1
  220. resources and direct the processing tools to the right subcatalog.</p>
  221. <h3>A subcatalog example:</h3>
  222. <p>Here is the complete subcatalog used for XHTML1:</p>
  223. <pre>&lt;?xml version="1.0"?&gt;
  224. &lt;!DOCTYPE catalog PUBLIC "-//OASIS//DTD Entity Resolution XML Catalog V1.0//EN"
  225. "http://www.oasis-open.org/committees/entity/release/1.0/catalog.dtd"&gt;
  226. &lt;catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog"&gt;
  227. &lt;public publicId="-//W3C//DTD XHTML 1.0 Strict//EN"
  228. uri="xhtml1-20020801/DTD/xhtml1-strict.dtd"/&gt;
  229. &lt;public publicId="-//W3C//DTD XHTML 1.0 Transitional//EN"
  230. uri="xhtml1-20020801/DTD/xhtml1-transitional.dtd"/&gt;
  231. &lt;public publicId="-//W3C//DTD XHTML 1.0 Frameset//EN"
  232. uri="xhtml1-20020801/DTD/xhtml1-frameset.dtd"/&gt;
  233. &lt;rewriteSystem systemIdStartString="http://www.w3.org/TR/xhtml1/DTD"
  234. rewritePrefix="xhtml1-20020801/DTD"/&gt;
  235. &lt;rewriteURI uriStartString="http://www.w3.org/TR/xhtml1/DTD"
  236. rewritePrefix="xhtml1-20020801/DTD"/&gt;
  237. &lt;/catalog&gt;</pre>
  238. <p>There are a few things to notice:</p>
  239. <ul>
  240. <li>this is an XML resource, it points to the DTD using Canonical URLs, the
  241. root element defines a namespace (but based on an URN not an HTTP
  242. URL).</li>
  243. <li>it contains 5 rules, the 3 first ones are direct mapping for the 3
  244. PUBLIC identifiers defined by the XHTML1 specification and associating
  245. them with the local resource containing the DTD, the 2 last ones are
  246. rewrite rules allowing to build the local filename for any URL based on
  247. "http://www.w3.org/TR/xhtml1/DTD", the local cache simplifies the rules by
  248. keeping the same structure as the on-line server at the Canonical URL</li>
  249. <li>the local resources are designated using URI references (the uri or
  250. rewritePrefix attributes), the base being the containing sub-catalog URL,
  251. which means that in practice the copy of the XHTML1 strict DTD is stored
  252. locally in
  253. <code>/usr/share/sgml/xhtml1/xmlcatalog/xhtml1-20020801/DTD/xhtml1-strict.dtd</code></li>
  254. </ul>
  255. <p>Those 5 rules are sufficient to cover all references to the resources held
  256. at the Canonical URL for the XHTML1 DTDs.</p>
  257. <h2><a name="Package">Package integration</a></h2>
  258. <p>Creating and removing catalogs should be handled as part of the process of
  259. (un)installing the local copy of the resources. The catalog files being XML
  260. resources should be processed with XML based tools to avoid problems with the
  261. generated files, the xmlcatalog command coming with libxml2 allows you to create
  262. catalogs, and add or remove rules at that time. Here is a complete example
  263. coming from the RPM for the XHTML1 DTDs post install script. While this example
  264. is platform and packaging specific, this can be useful as a an example in
  265. other contexts:</p>
  266. <pre>%post
  267. CATALOG=/usr/share/sgml/xhtml1/xmlcatalog
  268. #
  269. # Register it in the super catalog with the appropriate delegates
  270. #
  271. ROOTCATALOG=/etc/xml/catalog
  272. if [ ! -r $ROOTCATALOG ]
  273. then
  274. /usr/bin/xmlcatalog --noout --create $ROOTCATALOG
  275. fi
  276. if [ -w $ROOTCATALOG ]
  277. then
  278. /usr/bin/xmlcatalog --noout --add "delegatePublic" \
  279. "-//W3C//DTD XHTML 1.0" \
  280. "file://$CATALOG" $ROOTCATALOG
  281. /usr/bin/xmlcatalog --noout --add "delegateSystem" \
  282. "http://www.w3.org/TR/xhtml1/DTD" \
  283. "file://$CATALOG" $ROOTCATALOG
  284. /usr/bin/xmlcatalog --noout --add "delegateURI" \
  285. "http://www.w3.org/TR/xhtml1/DTD" \
  286. "file://$CATALOG" $ROOTCATALOG
  287. fi</pre>
  288. <p>The XHTML1 subcatalog is not created on-the-fly in that case, it is
  289. installed as part of the files of the packages. So the only work needed is to
  290. make sure the root catalog exists and register the delegate rules.</p>
  291. <p>Similarly, the script for the post-uninstall just remove the rules from the
  292. catalog:</p>
  293. <pre>%postun
  294. #
  295. # On removal, unregister the xmlcatalog from the supercatalog
  296. #
  297. if [ "$1" = 0 ]; then
  298. CATALOG=/usr/share/sgml/xhtml1/xmlcatalog
  299. ROOTCATALOG=/etc/xml/catalog
  300. if [ -w $ROOTCATALOG ]
  301. then
  302. /usr/bin/xmlcatalog --noout --del \
  303. "-//W3C//DTD XHTML 1.0" $ROOTCATALOG
  304. /usr/bin/xmlcatalog --noout --del \
  305. "http://www.w3.org/TR/xhtml1/DTD" $ROOTCATALOG
  306. /usr/bin/xmlcatalog --noout --del \
  307. "http://www.w3.org/TR/xhtml1/DTD" $ROOTCATALOG
  308. fi
  309. fi</pre>
  310. <p>Note the test against $1, this is needed to not remove the delegate rules
  311. in case of upgrade of the package.</p>
  312. <p>Following the set of guidelines and tips provided in this document should
  313. help deploy the XML resources in the GNOME framework without much pain and
  314. ensure a smooth evolution of the resource and instances.</p>
  315. <p><a href="mailto:veillard@redhat.com">Daniel Veillard</a></p>
  316. <p>$Id$</p>
  317. <p></p>
  318. </body>
  319. </html>