xref: /aosp_15_r20/external/google-styleguide/xmlstyle.html (revision 8c35d5ee8e2913d4bd6623e2b93232b1da0ab719)
1*8c35d5eeSXin Li<style type="text/css">
2*8c35d5eeSXin Li/* default css */
3*8c35d5eeSXin Litable {
4*8c35d5eeSXin Lifont-size: 1em;
5*8c35d5eeSXin Liline-height: inherit;
6*8c35d5eeSXin Li}
7*8c35d5eeSXin Litr {
8*8c35d5eeSXin Litext-align: left;
9*8c35d5eeSXin Li}
10*8c35d5eeSXin Lidiv, address, ol, ul, li, option, select {
11*8c35d5eeSXin Limargin-top: 0px;
12*8c35d5eeSXin Limargin-bottom: 0px;
13*8c35d5eeSXin Li}
14*8c35d5eeSXin Lip {
15*8c35d5eeSXin Limargin: 0px;
16*8c35d5eeSXin Li}
17*8c35d5eeSXin Libody {
18*8c35d5eeSXin Limargin: 6px;
19*8c35d5eeSXin Lipadding: 0px;
20*8c35d5eeSXin Lifont-family: Verdana, sans-serif;
21*8c35d5eeSXin Lifont-size: 10pt;
22*8c35d5eeSXin Libackground-color: #ffffff;
23*8c35d5eeSXin Li}
24*8c35d5eeSXin Liimg {
25*8c35d5eeSXin Li-moz-force-broken-image-icon: 1;
26*8c35d5eeSXin Li}
27*8c35d5eeSXin Li@media screen {
28*8c35d5eeSXin Lihtml.pageview {
29*8c35d5eeSXin Libackground-color: #f3f3f3 !important;
30*8c35d5eeSXin Li}
31*8c35d5eeSXin Libody {
32*8c35d5eeSXin Limin-height: 1100px;
33*8c35d5eeSXin Licounter-reset: __goog_page__;
34*8c35d5eeSXin Li}
35*8c35d5eeSXin Li* html body {
36*8c35d5eeSXin Liheight: 1100px;
37*8c35d5eeSXin Li}
38*8c35d5eeSXin Li.pageview body {
39*8c35d5eeSXin Liborder-top: 1px solid #ccc;
40*8c35d5eeSXin Liborder-left: 1px solid #ccc;
41*8c35d5eeSXin Liborder-right: 2px solid #bbb;
42*8c35d5eeSXin Liborder-bottom: 2px solid #bbb;
43*8c35d5eeSXin Liwidth: 648px !important;
44*8c35d5eeSXin Limargin: 15px auto 25px;
45*8c35d5eeSXin Lipadding: 40px 50px;
46*8c35d5eeSXin Li}
47*8c35d5eeSXin Li/* IE6 */
48*8c35d5eeSXin Li* html {
49*8c35d5eeSXin Lioverflow-y: scroll;
50*8c35d5eeSXin Li}
51*8c35d5eeSXin Li* html.pageview body {
52*8c35d5eeSXin Lioverflow-x: auto;
53*8c35d5eeSXin Li}
54*8c35d5eeSXin Li/* Prevent repaint errors when scrolling in Safari. This "Star-7" css hack
55*8c35d5eeSXin Litargets Safari 3.1, but not WebKit nightlies and presumably Safari 4.
56*8c35d5eeSXin LiThat's OK because this bug is fixed in WebKit nightlies/Safari 4 :-). */
57*8c35d5eeSXin Lihtml*#wys_frame::before {
58*8c35d5eeSXin Licontent: '\A0';
59*8c35d5eeSXin Liposition: fixed;
60*8c35d5eeSXin Lioverflow: hidden;
61*8c35d5eeSXin Liwidth: 0;
62*8c35d5eeSXin Liheight: 0;
63*8c35d5eeSXin Litop: 0;
64*8c35d5eeSXin Lileft: 0;
65*8c35d5eeSXin Li}
66*8c35d5eeSXin Li.writely-callout-data {
67*8c35d5eeSXin Lidisplay: none;
68*8c35d5eeSXin Li*display: inline-block;
69*8c35d5eeSXin Li*width: 0;
70*8c35d5eeSXin Li*height: 0;
71*8c35d5eeSXin Li*overflow: hidden;
72*8c35d5eeSXin Li}
73*8c35d5eeSXin Li.writely-footnote-marker {
74*8c35d5eeSXin Libackground-image: url('images/footnote_doc_icon.gif');
75*8c35d5eeSXin Libackground-color: transparent;
76*8c35d5eeSXin Libackground-repeat: no-repeat;
77*8c35d5eeSXin Liwidth: 7px;
78*8c35d5eeSXin Lioverflow: hidden;
79*8c35d5eeSXin Liheight: 16px;
80*8c35d5eeSXin Livertical-align: top;
81*8c35d5eeSXin Li-moz-user-select: none;
82*8c35d5eeSXin Li}
83*8c35d5eeSXin Li.editor .writely-footnote-marker {
84*8c35d5eeSXin Licursor: move;
85*8c35d5eeSXin Li}
86*8c35d5eeSXin Li.writely-footnote-marker-highlight {
87*8c35d5eeSXin Libackground-position: -15px 0;
88*8c35d5eeSXin Li-moz-user-select: text;
89*8c35d5eeSXin Li}
90*8c35d5eeSXin Li.writely-footnote-hide-selection ::-moz-selection, .writely-footnote-hide-selection::-moz-selection {
91*8c35d5eeSXin Libackground: transparent;
92*8c35d5eeSXin Li}
93*8c35d5eeSXin Li.writely-footnote-hide-selection ::selection, .writely-footnote-hide-selection::selection {
94*8c35d5eeSXin Libackground: transparent;
95*8c35d5eeSXin Li}
96*8c35d5eeSXin Li.writely-footnote-hide-selection {
97*8c35d5eeSXin Licursor: move;
98*8c35d5eeSXin Li}
99*8c35d5eeSXin Li.editor .writely-comment-yellow {
100*8c35d5eeSXin Libackground-color: #FF9;
101*8c35d5eeSXin Libackground-position: -240px 0;
102*8c35d5eeSXin Li}
103*8c35d5eeSXin Li.editor .writely-comment-yellow-hover {
104*8c35d5eeSXin Libackground-color: #FF0;
105*8c35d5eeSXin Libackground-position: -224px 0;
106*8c35d5eeSXin Li}
107*8c35d5eeSXin Li.editor .writely-comment-blue {
108*8c35d5eeSXin Libackground-color: #C0D3FF;
109*8c35d5eeSXin Libackground-position: -16px 0;
110*8c35d5eeSXin Li}
111*8c35d5eeSXin Li.editor .writely-comment-blue-hover {
112*8c35d5eeSXin Libackground-color: #6292FE;
113*8c35d5eeSXin Libackground-position: 0 0;
114*8c35d5eeSXin Li}
115*8c35d5eeSXin Li.editor .writely-comment-orange {
116*8c35d5eeSXin Libackground-color: #FFDEAD;
117*8c35d5eeSXin Libackground-position: -80px 0;
118*8c35d5eeSXin Li}
119*8c35d5eeSXin Li.editor .writely-comment-orange-hover {
120*8c35d5eeSXin Libackground-color: #F90;
121*8c35d5eeSXin Libackground-position: -64px 0;
122*8c35d5eeSXin Li}
123*8c35d5eeSXin Li.editor .writely-comment-green {
124*8c35d5eeSXin Libackground-color: #99FBB3;
125*8c35d5eeSXin Libackground-position: -48px 0;
126*8c35d5eeSXin Li}
127*8c35d5eeSXin Li.editor .writely-comment-green-hover {
128*8c35d5eeSXin Libackground-color: #00F442;
129*8c35d5eeSXin Libackground-position: -32px 0;
130*8c35d5eeSXin Li}
131*8c35d5eeSXin Li.editor .writely-comment-cyan {
132*8c35d5eeSXin Libackground-color: #CFF;
133*8c35d5eeSXin Libackground-position: -208px 0;
134*8c35d5eeSXin Li}
135*8c35d5eeSXin Li.editor .writely-comment-cyan-hover {
136*8c35d5eeSXin Libackground-color: #0FF;
137*8c35d5eeSXin Libackground-position: -192px 0;
138*8c35d5eeSXin Li}
139*8c35d5eeSXin Li.editor .writely-comment-purple {
140*8c35d5eeSXin Libackground-color: #EBCCFF;
141*8c35d5eeSXin Libackground-position: -144px 0;
142*8c35d5eeSXin Li}
143*8c35d5eeSXin Li.editor .writely-comment-purple-hover {
144*8c35d5eeSXin Libackground-color: #90F;
145*8c35d5eeSXin Libackground-position: -128px 0;
146*8c35d5eeSXin Li}
147*8c35d5eeSXin Li.editor .writely-comment-magenta {
148*8c35d5eeSXin Libackground-color: #FCF;
149*8c35d5eeSXin Libackground-position: -112px 0;
150*8c35d5eeSXin Li}
151*8c35d5eeSXin Li.editor .writely-comment-magenta-hover {
152*8c35d5eeSXin Libackground-color: #F0F;
153*8c35d5eeSXin Libackground-position: -96px 0;
154*8c35d5eeSXin Li}
155*8c35d5eeSXin Li.editor .writely-comment-red {
156*8c35d5eeSXin Libackground-color: #FFCACA;
157*8c35d5eeSXin Libackground-position: -176px 0;
158*8c35d5eeSXin Li}
159*8c35d5eeSXin Li.editor .writely-comment-red-hover {
160*8c35d5eeSXin Libackground-color: #FF7A7A;
161*8c35d5eeSXin Libackground-position: -160px 0;
162*8c35d5eeSXin Li}
163*8c35d5eeSXin Li.editor .writely-comment-marker {
164*8c35d5eeSXin Libackground-image: url('images/markericons_horiz.gif');
165*8c35d5eeSXin Libackground-color: transparent;
166*8c35d5eeSXin Lipadding-right: 11px;
167*8c35d5eeSXin Libackground-repeat: no-repeat;
168*8c35d5eeSXin Liwidth: 16px;
169*8c35d5eeSXin Liheight: 16px;
170*8c35d5eeSXin Li-moz-user-select: none;
171*8c35d5eeSXin Li}
172*8c35d5eeSXin Li.editor .writely-comment-hidden {
173*8c35d5eeSXin Lipadding: 0;
174*8c35d5eeSXin Libackground: none;
175*8c35d5eeSXin Li}
176*8c35d5eeSXin Li.editor .writely-comment-marker-hidden {
177*8c35d5eeSXin Libackground: none;
178*8c35d5eeSXin Lipadding: 0;
179*8c35d5eeSXin Liwidth: 0;
180*8c35d5eeSXin Li}
181*8c35d5eeSXin Li.editor .writely-comment-none {
182*8c35d5eeSXin Liopacity: .2;
183*8c35d5eeSXin Lifilter:progid:DXImageTransform.Microsoft.Alpha(opacity=20);
184*8c35d5eeSXin Li-moz-opacity: .2;
185*8c35d5eeSXin Li}
186*8c35d5eeSXin Li.editor .writely-comment-none-hover {
187*8c35d5eeSXin Liopacity: .2;
188*8c35d5eeSXin Lifilter:progid:DXImageTransform.Microsoft.Alpha(opacity=20);
189*8c35d5eeSXin Li-moz-opacity: .2;
190*8c35d5eeSXin Li}
191*8c35d5eeSXin Li.br_fix br:not(:-moz-last-node):not(:-moz-first-node) {
192*8c35d5eeSXin Liposition:relative;
193*8c35d5eeSXin Lileft: -1ex
194*8c35d5eeSXin Li}
195*8c35d5eeSXin Li.br_fix br+br {
196*8c35d5eeSXin Liposition: static !important
197*8c35d5eeSXin Li}
198*8c35d5eeSXin Li}
199*8c35d5eeSXin Lih6 { font-size: 8pt }
200*8c35d5eeSXin Lih5 { font-size: 8pt }
201*8c35d5eeSXin Lih4 { font-size: 10pt }
202*8c35d5eeSXin Lih3 { font-size: 12pt }
203*8c35d5eeSXin Lih2 { font-size: 14pt }
204*8c35d5eeSXin Lih1 { font-size: 18pt }
205*8c35d5eeSXin Liblockquote {padding: 10px; border: 1px #DDD dashed }
206*8c35d5eeSXin Lia img {border: 0}
207*8c35d5eeSXin Li.pb {
208*8c35d5eeSXin Liborder-width: 0;
209*8c35d5eeSXin Lipage-break-after: always;
210*8c35d5eeSXin Li/* We don't want this to be resizeable, so enforce a width and height
211*8c35d5eeSXin Liusing !important */
212*8c35d5eeSXin Liheight: 1px !important;
213*8c35d5eeSXin Liwidth: 100% !important;
214*8c35d5eeSXin Li}
215*8c35d5eeSXin Li.editor .pb {
216*8c35d5eeSXin Liborder-top: 1px dashed #C0C0C0;
217*8c35d5eeSXin Liborder-bottom: 1px dashed #C0C0C0;
218*8c35d5eeSXin Li}
219*8c35d5eeSXin Lidiv.google_header, div.google_footer {
220*8c35d5eeSXin Liposition: relative;
221*8c35d5eeSXin Limargin-top: 1em;
222*8c35d5eeSXin Limargin-bottom: 1em;
223*8c35d5eeSXin Li}
224*8c35d5eeSXin Li/* Table of contents */
225*8c35d5eeSXin Li.editor div.writely-toc {
226*8c35d5eeSXin Libackground-color: #f3f3f3;
227*8c35d5eeSXin Liborder: 1px solid #ccc;
228*8c35d5eeSXin Li}
229*8c35d5eeSXin Li.writely-toc > ol {
230*8c35d5eeSXin Lipadding-left: 3em;
231*8c35d5eeSXin Lifont-weight: bold;
232*8c35d5eeSXin Li}
233*8c35d5eeSXin Liol.writely-toc-subheading {
234*8c35d5eeSXin Lipadding-left: 1em;
235*8c35d5eeSXin Lifont-weight: normal;
236*8c35d5eeSXin Li}
237*8c35d5eeSXin Li/* IE6 only */
238*8c35d5eeSXin Li* html writely-toc ol {
239*8c35d5eeSXin Lilist-style-position: inside;
240*8c35d5eeSXin Li}
241*8c35d5eeSXin Li.writely-toc-none {
242*8c35d5eeSXin Lilist-style-type: none;
243*8c35d5eeSXin Li}
244*8c35d5eeSXin Li.writely-toc-decimal {
245*8c35d5eeSXin Lilist-style-type: decimal;
246*8c35d5eeSXin Li}
247*8c35d5eeSXin Li.writely-toc-upper-alpha {
248*8c35d5eeSXin Lilist-style-type: upper-alpha;
249*8c35d5eeSXin Li}
250*8c35d5eeSXin Li.writely-toc-lower-alpha {
251*8c35d5eeSXin Lilist-style-type: lower-alpha;
252*8c35d5eeSXin Li}
253*8c35d5eeSXin Li.writely-toc-upper-roman {
254*8c35d5eeSXin Lilist-style-type: upper-roman;
255*8c35d5eeSXin Li}
256*8c35d5eeSXin Li.writely-toc-lower-roman {
257*8c35d5eeSXin Lilist-style-type: lower-roman;
258*8c35d5eeSXin Li}
259*8c35d5eeSXin Li.writely-toc-disc {
260*8c35d5eeSXin Lilist-style-type: disc;
261*8c35d5eeSXin Li}
262*8c35d5eeSXin Li/* Ordered lists converted to numbered lists can preserve ordered types, and
263*8c35d5eeSXin Livice versa. This is confusing, so disallow it */
264*8c35d5eeSXin Liul[type="i"], ul[type="I"], ul[type="1"], ul[type="a"], ul[type="A"] {
265*8c35d5eeSXin Lilist-style-type: disc;
266*8c35d5eeSXin Li}
267*8c35d5eeSXin Liol[type="disc"], ol[type="circle"], ol[type="square"] {
268*8c35d5eeSXin Lilist-style-type: decimal;
269*8c35d5eeSXin Li}
270*8c35d5eeSXin Li/* end default css */
271*8c35d5eeSXin Li/* custom css */
272*8c35d5eeSXin Li/* end custom css */
273*8c35d5eeSXin Li/* ui edited css */
274*8c35d5eeSXin Libody {
275*8c35d5eeSXin Lifont-family: Verdana;
276*8c35d5eeSXin Lifont-size: 10.0pt;
277*8c35d5eeSXin Liline-height: normal;
278*8c35d5eeSXin Libackground-color: #ffffff;
279*8c35d5eeSXin Li}
280*8c35d5eeSXin Li/* end ui edited css */
281*8c35d5eeSXin Li/* editor CSS */
282*8c35d5eeSXin Li.editor a:visited {color: #551A8B}
283*8c35d5eeSXin Li.editor table.zeroBorder {border: 1px dotted gray}
284*8c35d5eeSXin Li.editor table.zeroBorder td {border: 1px dotted gray}
285*8c35d5eeSXin Li.editor table.zeroBorder th {border: 1px dotted gray}
286*8c35d5eeSXin Li.editor div.google_header, .editor div.google_footer {
287*8c35d5eeSXin Liborder: 2px #DDDDDD dashed;
288*8c35d5eeSXin Liposition: static;
289*8c35d5eeSXin Liwidth: 100%;
290*8c35d5eeSXin Limin-height: 2em;
291*8c35d5eeSXin Li}
292*8c35d5eeSXin Li.editor .misspell {background-color: yellow}
293*8c35d5eeSXin Li.editor .writely-comment {
294*8c35d5eeSXin Lifont-size: 9pt;
295*8c35d5eeSXin Liline-height: 1.4;
296*8c35d5eeSXin Lipadding: 1px;
297*8c35d5eeSXin Liborder: 1px dashed #C0C0C0
298*8c35d5eeSXin Li}
299*8c35d5eeSXin Li/* end editor CSS */
300*8c35d5eeSXin Li</style>
301*8c35d5eeSXin Li<style>
302*8c35d5eeSXin Libody {
303*8c35d5eeSXin Limargin: 0px;
304*8c35d5eeSXin Li}
305*8c35d5eeSXin Li#doc-contents {
306*8c35d5eeSXin Limargin: 6px;
307*8c35d5eeSXin Li}
308*8c35d5eeSXin Li#google-view-footer {
309*8c35d5eeSXin Liclear: both;
310*8c35d5eeSXin Liborder-top: thin solid;
311*8c35d5eeSXin Lipadding-top: 0.3em;
312*8c35d5eeSXin Lipadding-bottom: 0.3em;
313*8c35d5eeSXin Li}
314*8c35d5eeSXin Lia.google-small-link:link, a.google-small-link:visited {
315*8c35d5eeSXin Licolor:#112ABB;
316*8c35d5eeSXin Lifont-family:Arial,Sans-serif;
317*8c35d5eeSXin Lifont-size:11px !important;
318*8c35d5eeSXin Li}
319*8c35d5eeSXin Libody, p, div, td {
320*8c35d5eeSXin Lidirection: inherit;
321*8c35d5eeSXin Li}
322*8c35d5eeSXin Li@media print {
323*8c35d5eeSXin Li#google-view-footer {
324*8c35d5eeSXin Lidisplay: none;
325*8c35d5eeSXin Li}
326*8c35d5eeSXin Li}
327*8c35d5eeSXin Li</style>
328*8c35d5eeSXin Li<script>
329*8c35d5eeSXin Lifunction viewOnLoad() {
330*8c35d5eeSXin Liif (document.location.href.indexOf('spi=1') != -1) {
331*8c35d5eeSXin Liif (navigator.userAgent.toLowerCase().indexOf('msie') != -1) {
332*8c35d5eeSXin Liwindow.print();
333*8c35d5eeSXin Li} else {
334*8c35d5eeSXin Liwindow.setTimeout(window.print, 10);
335*8c35d5eeSXin Li}
336*8c35d5eeSXin Li}
337*8c35d5eeSXin Liif (document.location.href.indexOf('hgd=1') != -1) {
338*8c35d5eeSXin Livar footer = document.getElementById("google-view-footer");
339*8c35d5eeSXin Liif (footer) {
340*8c35d5eeSXin Lifooter.style.display = 'none';
341*8c35d5eeSXin Li}
342*8c35d5eeSXin Li}
343*8c35d5eeSXin Li}
344*8c35d5eeSXin Li</script>
345*8c35d5eeSXin Li</head>
346*8c35d5eeSXin Li<body>
347*8c35d5eeSXin Li<div id="doc-contents">
348*8c35d5eeSXin Li<div>
349*8c35d5eeSXin Li
350*8c35d5eeSXin Li<h1 style="text-align: center;">
351*8c35d5eeSXin LiGoogle XML Document Format Style Guide</h1><div style="text-align: center;">Version 1.0<br>Copyright Google 2008<br><br></div><h2>Introduction</h2>This document provides a set of guidelines for general use when designing new XML document formats (and to some extent XML documents as well; see Section 11).&nbsp; Document formats usually include both formal parts (DTDs, schemas) and parts expressed in normative English prose.<br><br>These guidelines apply to new designs, and are not intended to force retroactive changes in existing designs.&nbsp; When participating in the creation of public or private document format designs, the guidelines may be helpful but should not control the group consensus.<br><br>This guide is meant for the design of XML that is to be generated and consumed by machines rather than human beings.&nbsp; Its rules are <i>not applicable</i> to formats such as XHTML (which should be formatted as much like HTML as possible) or ODF which are meant to express rich text.&nbsp; A document that includes embedded content in XHTML or some other rich-text format, but also contains purely machine-interpretable portions, SHOULD follow this style guide for the machine-interpretable portions.&nbsp; It also does not affect XML document formats that are created by translations from proto buffers or through some other type of format.<br><br>Brief rationales have been added to most of the guidelines.&nbsp; They are maintained in the same document in hopes that they won't get out of date, but they are not considered normative.<br><br>The terms MUST, MUST NOT, SHOULD, SHOULD NOT, and MAY are used in this document in the sense of <a title="RFC 2119" href="https://www.ietf.org/rfc/rfc2119.txt" id="iecm">RFC 2119.</a><br>&nbsp;<br><h2>1. To design or not to design, that is the question<br></h2><ol><li>Attempt to reuse existing XML formats whenever possible, especially those which allow extensions.&nbsp; Creating an entirely new format should be done only with care and consideration; read <a title="Tim Bray's warnings" href="https://www.tbray.org/ongoing/When/200x/2006/01/08/No-New-XML-Languages" id="d3cy">Tim Bray's warnings</a> first.&nbsp; Try to get wide review of your format, from outside your organization as well, if possible.&nbsp; [<i>Rationale:</i> New document formats have a cost: they must be reviewed, documented, and learned by users.]<br><br></li><li>If you are reusing or extending an existing format, make <i>sensible</i>
352*8c35d5eeSXin Li
353*8c35d5eeSXin Liuse of the prescribed elements and attributes, especially any that are
354*8c35d5eeSXin Lirequired.&nbsp; Don't completely repurpose them, but do try to see how they
355*8c35d5eeSXin Limight be used in creative ways if the vanilla semantics aren't
356*8c35d5eeSXin Lisuitable.&nbsp; As a last resort when an element or attribute is required by the format but is not appropriate for your use case, use some
357*8c35d5eeSXin Lifixed string as its value.&nbsp; [<i>Rationale:</i>&nbsp; Markup reuse is good, markup abuse is bad.]<br><br></li><li>When extending formats, use the implicit style of the existing format, even if it contradicts this guide.&nbsp; [<i>Rationale: </i>Consistency.]<br></li></ol><br><h2>2. Schemas</h2><ol><li>Document formats SHOULD be expressed using a schema language.&nbsp; [<i>Rationale: </i>Clarity and machine-checkability.]<br><br></li><li>The schema language SHOULD be <a title="RELAX NG" href="http://www.relaxng.org/" id="p1s7">RELAX NG</a> <a title="compact syntax" href="http://www.relaxng.org/compact-tutorial-20030326.html" id="ulci">compact syntax</a>.&nbsp; Embedded <a title="Schematron" href="http://www.schematron.com/" id="ymh-">Schematron</a> rules MAY be added to the schema for additional fine control.&nbsp; [<i>Rationale:</i>
358*8c35d5eeSXin Li
359*8c35d5eeSXin LiRELAX NG is the most flexible schema language, with very few arbitrary
360*8c35d5eeSXin Lirestrictions on designs.&nbsp; The compact syntax is quite easy to read and
361*8c35d5eeSXin Lilearn, and can be converted one-to-one to and from the XML syntax when
362*8c35d5eeSXin Linecessary.&nbsp; Schematron handles arbitrary cross-element and
363*8c35d5eeSXin Licross-attribute constraints nicely.]<br><br></li><li>Schemas SHOULD use the <a title="&quot;Salami Slice&quot; style" href="http://www.xfront.com/GlobalVersusLocal.html#SecondDesign" id="r:fj">"Salami Slice" style</a> (one rule per element).&nbsp; Schemas MAY use the <a title="&quot;Russian Doll&quot; style" href="http://www.xfront.com/GlobalVersusLocal.html#FirstDesign" id="h14y">"Russian Doll" style</a> (schema resembles document) if they are short and simple.&nbsp; The <a title="&quot;Venetian Blind&quot; style" href="http://www.xfront.com/GlobalVersusLocal.html#ThirdDesign" id="dr_g">"Venetian Blind" style</a> (one rule per element type) is unsuited to RELAX NG and SHOULD NOT be used.<br><br></li><li>Regular expressions SHOULD be provided to assist in validating complex values.<br><br></li><li>DTDs and/or W3C XML Schemas MAY be provided for compatibility with existing products, tools, or users.&nbsp; [<i>Rationale:</i> We can't change the world all at once.]<br></li></ol></div><div><br><h2>3. Namespaces</h2><ol><li>Element names MUST be in a namespace, except
364*8c35d5eeSXin Liwhen extending pre-existing document types that do not use namespaces.&nbsp;
365*8c35d5eeSXin Li
366*8c35d5eeSXin LiA default namespace SHOULD be used.&nbsp; [<i>Rationale:</i> Namespace-free
367*8c35d5eeSXin Lidocuments are obsolete; every set of names should be in some
368*8c35d5eeSXin Linamespace.&nbsp; Using a default namespace improves readability.]<br><br></li><li>Attribute
369*8c35d5eeSXin Linames SHOULD NOT be in a namespace unless they are drawn from a foreign
370*8c35d5eeSXin Lidocument type or are meant to be used in foreign document types.&nbsp; [<i>Rationale:</i> Attribute names in a namespace must always have a prefix, which is annoying to type and hard to read.]<br><br>
371*8c35d5eeSXin Li</li><li>Namespace names are HTTP URIs.&nbsp; Namespace names SHOULD take the form <span style="font-family: Courier New;">https://example.com/</span><i style="font-family: Courier New;">whatever</i><span style="font-family: Courier New;">/</span><i><span style="font-family: Courier New;">year</span>, </i>where <i>whatever</i> is a unique value based on the name of the document type, and <i>year</i>
372*8c35d5eeSXin Li
373*8c35d5eeSXin Liis the year the namespace was created.&nbsp; There may be additional URI-path parts
374*8c35d5eeSXin Libefore the <i>year.</i>&nbsp; [<i>Rationale:</i> Existing convention.&nbsp; Providing the year allows for the possible recycling of code names.]<br><br></li><li>Namespaces MUST NOT be changed unless the semantics of particular elements or attributes has changed in drastically incompatible ways.&nbsp; [<i>Rationale:</i> Changing the namespace requires changing all client code.]<br><br></li><li>Namespace prefixes SHOULD be short (but not so short that they are likely to be conflict with another project).&nbsp; Single-letter prefixes MUST NOT be used. Prefixes SHOULD contain only lower-case ASCII letters.&nbsp; [<i>Rationale:</i> Ease of typing and absence of encoding compatibility problems.]</li></ol><br>
375*8c35d5eeSXin Li
376*8c35d5eeSXin Li<h2>4. Names and enumerated values</h2><b>Note: </b>"Names" refers to the names of elements, attributes, and enumerated values.<br><br><ol><li>All names MUST use lowerCamelCase. That is, they start with an initial lower-case letter, then each new word within the name starts with an initial capital letter. [<i>Rationale:</i> Adopting a single style provides consistency, which helps when referring to names since the capitalization is known and so does not have to be remembered.&nbsp; It matches Java style, and other languages can be dealt with using automated name conversion.]<br><br></li><li>Names MUST contain only ASCII letters and digits.&nbsp;
377*8c35d5eeSXin Li[<i>Rationale:</i> Ease of typing and absence of encoding compatibility problems.]<br> <br></li><li>Names SHOULD NOT exceed 25 characters. Longer names SHOULD be
378*8c35d5eeSXin Liavoided by devising concise and informative names.&nbsp; If a name can only remain within this limit by becoming obscure, the limit SHOULD be ignored.&nbsp; [<i>Rationale: </i>Longer names are awkward to use and require additional bandwidth.]<br><br></li><li>Published standard abbreviations, if sufficiently well-known, MAY be employed in constructing names. Ad hoc abbreviations MUST NOT be used.&nbsp; Acronyms MUST be treated as words for camel-casing purposes: informationUri, not informationURI. [<i>Rationale:</i>&nbsp; An abbreviation that is well known
379*8c35d5eeSXin Lito one community is often incomprehensible to others who need to use
380*8c35d5eeSXin Lithe same document format (and who do understand the full name); treating an acronym as a word makes it easier to see where the word boundaries are.] <br></li></ol><p><br></p><p>
381*8c35d5eeSXin Li
382*8c35d5eeSXin Li</p><h2>
383*8c35d5eeSXin Li5. Elements</h2><ol><li>All elements MUST contain either nothing, character content, or child elements.&nbsp; Mixed content MUST NOT be used.&nbsp; [<i>Rationale:</i> Many XML data models don't handle mixed content properly, and its use makes the element order-dependent.&nbsp; As always, textual formats are not covered by this rule.]<br><br></li><li>XML elements that merely wrap repeating child elements SHOULD NOT be used.&nbsp; [<i>Rationale:</i> They are not used in Atom and add nothing.]</li></ol>
384*8c35d5eeSXin Li
385*8c35d5eeSXin Li<p><br></p><h2>6. Attributes</h2><ol><li>Document formats MUST NOT depend on the order of attributes in a start-tag.&nbsp; [<i>Rationale:</i> Few XML parsers report the order, and it is not part of the XML Infoset.]<br><br></li><li>Elements SHOULD NOT be overloaded with too many attributes (no more
386*8c35d5eeSXin Lithan 10 as a rule of thumb).&nbsp; Instead, use child elements to
387*8c35d5eeSXin Liencapsulate closely related attributes.&nbsp; [<i>Rationale:</i> This
388*8c35d5eeSXin Liapproach maintains the built-in extensibility that XML provides with
389*8c35d5eeSXin Lielements, and is useful for providing forward compatibility as a
390*8c35d5eeSXin Lispecification evolves.]<br><br></li><li>Attributes MUST NOT be used to hold values in which line breaks are significant.&nbsp; [<i>Rationale:</i> Such line breaks are converted to spaces by conformant XML parsers.]<br><br></li><li>Document formats MUST allow either single or double quotation marks around attribute values.&nbsp; [<i>Rationale:</i>&nbsp; XML parsers don't report the difference.]<br></li></ol>
391*8c35d5eeSXin Li
392*8c35d5eeSXin Li<p><br></p>
393*8c35d5eeSXin Li<p>
394*8c35d5eeSXin Li</p><h2>
395*8c35d5eeSXin Li7. Values</h2><ol><li>Numeric values SHOULD be 32-bit signed integers, 64-bit signed integers, or 64-bit IEEE doubles, all expressed in base 10.&nbsp; These correspond to the XML Schema types <span style="font-family: Courier New;">xsd:int</span>, <span style="font-family: Courier New;">xsd:long</span>, and <span style="font-family: Courier New;">xsd:double</span> respectively.&nbsp; If required in particular cases, <span style="font-family: Courier New;">xsd:integer</span> (unlimited-precision integer) values MAY also be used.&nbsp; [<i>Rationale:</i> There are far too many numeric types in XML Schema: these provide a reasonable subset.]&nbsp; <br><br></li><li>
396*8c35d5eeSXin Li
397*8c35d5eeSXin LiBoolean values SHOULD NOT be used (use enumerations instead).&nbsp; If they must be used, they MUST be expressed as <span style="font-family: Courier New;">true</span> or <span style="font-family: Courier New;">false</span>, corresponding to a subset of the XML Schema type <span style="font-family: Courier New;">xsd:boolean</span>.&nbsp; The alternative <span style="font-family: Courier New;">xsd:boolean</span> values <span style="font-family: Courier New;">1</span> and <span style="font-family: Courier New;">0</span> MUST NOT be used.&nbsp; [<i>Rationale:</i> Boolean arguments are not extensible.&nbsp; The additional flexibility of allowing numeric values is not abstracted away by any parser.]<br><br></li><li>Dates should be represented using <a title="RFC 3339" href="https://www.ietf.org/rfc/rfc3339.txt" id="sk98">RFC 3339</a> format, a subset of both
398*8c35d5eeSXin LiISO 8601 format and XML Schema <span style="font-family: Courier New;">xsd:dateTime</span> format.&nbsp; UTC times SHOULD be used rather than local times.&nbsp;
399*8c35d5eeSXin Li
400*8c35d5eeSXin Li[<i>Rationale:</i> There are far too many date formats and time zones, although it is recognized that sometimes local time preserves important information.]<br><br></li><li>Embedded syntax in character content and attribute values SHOULD NOT be
401*8c35d5eeSXin Liused.&nbsp; Syntax in values means XML tools are largely useless.&nbsp; Syntaxes such as&nbsp; dates, URIs, and
402*8c35d5eeSXin LiXPath expressions are exceptions.&nbsp; [<i>Rationale:</i>&nbsp;
403*8c35d5eeSXin LiUsers should be able to process XML documents using only an XML parser
404*8c35d5eeSXin Liwithout requiring additional special-purpose parsers, which are easy to
405*8c35d5eeSXin Liget wrong.]<br><br></li><li>Be careful with whitespace in values.&nbsp; XML parsers don't strip whitespace in elements, but do convert newlines to spaces in attributes.&nbsp; However, application frameworks may do more aggressive whitespace stripping.&nbsp; Your document format SHOULD give rules for whitespace stripping.<br></li></ol>
406*8c35d5eeSXin Li
407*8c35d5eeSXin Li<p><br>
408*8c35d5eeSXin Li</p>
409*8c35d5eeSXin Li<p>
410*8c35d5eeSXin Li</p><h2>8. Key-value pairs<br></h2><ol><li>
411*8c35d5eeSXin LiSimple key-value pairs SHOULD be represented with an empty element whose name represents the key, with the <span style="font-family: Courier New;">value</span> attribute containing the value. Elements that have a <span style="font-family: Courier New;">value</span> attribute MAY also have a <span style="font-family: Courier New;">unit</span> attribute to specify the unit of a measured value.&nbsp; For physical measurements, the <a title="SI system" href="https://en.wikipedia.org/wiki/International_System_of_Units" id="rhxg">SI system</a> SHOULD be used.&nbsp; [<i>Rationale:</i>
412*8c35d5eeSXin Li
413*8c35d5eeSXin LiSimplicity and design consistency.&nbsp; Keeping the value in an attribute
414*8c35d5eeSXin Lihides it from the user, since displaying just the value without the key is not useful.]<br><br></li><li>If the number of possible keys is very large or unbounded, key-value pairs MAY be represented by a single generic element with <span style="font-family: Courier New;">key</span>, <span style="font-family: Courier New;">value</span>, and optional <span style="font-family: Courier New;">unit</span> and <span style="font-family: Courier New;">scheme</span>
415*8c35d5eeSXin Liattributes (which serve to discriminate keys from different domains).&nbsp;
416*8c35d5eeSXin LiIn that case, also provide (not necessarily in the same document) a
417*8c35d5eeSXin Lilist of keys with human-readable explanations.</li></ol><br><h2>9. Binary data</h2><p><b>Note: </b>There are no hard and fast rules about whether binary data should be included as part of an XML document or not.&nbsp; If it's too large, it's probably better to link to it.</p><p><br></p><ol><li>Binary data MUST NOT be included directly as-is in XML documents, but MUST be encoded using Base64 encoding.&nbsp; [<i>Rationale:</i> XML does not allow arbitrary binary bytes.]<br><br></li><li>
418*8c35d5eeSXin Li
419*8c35d5eeSXin LiThe line breaks required by Base64 MAY be omitted.&nbsp; [<i>Rationale:</i> The line breaks are meant to keep plain text lines short, but XML is not really plain text.]<br><br></li><li>An attribute named <span style="font-family: Courier New;">xsi:type</span> with value <span style="font-family: Courier New;">xs:base64Binary</span> MAY be attached to this element to signal that the Base64 format is in use.&nbsp; [Rationale: Opaque blobs should have decoding instructions attached.]<br><br></li></ol>
420*8c35d5eeSXin Li<h2>10. Processing instructions</h2><ol><li>New processing instructions MUST NOT be created except in order to specify purely local processing conventions, and SHOULD be avoided altogether.&nbsp; Existing standardized processing instructions MAY be used.&nbsp; [<i>Rationale:</i> Processing instructions fit awkwardly into XML data models and can always be replaced by elements; they exist primarily to avoid breaking backward compatibility.]</li></ol><p>&nbsp;</p>
421*8c35d5eeSXin Li
422*8c35d5eeSXin Li<p>
423*8c35d5eeSXin Li</p><p>&nbsp;</p><h2>11. Representation of XML document instances<br></h2><p><b>Note:</b>&nbsp; These points are only guidelines, as the format of program-created instances will often be outside the programmer's control (for example, when an XML serialization library is being used).&nbsp; <i>In no case</i> should XML parsers rely on these guidelines being followed.&nbsp; Use standard XML parsers, not hand-rolled hacks.<br></p><p><br></p><ol><li>The character encoding used SHOULD be UTF-8.&nbsp; Exceptions should require extremely compelling circumstances.&nbsp; [<i>Rationale:</i> UTF-8 is universal and in common use.]<br><br></li><li>Namespaces SHOULD be declared in the root element of a document wherever possible.&nbsp; [<i>Rationale: </i>Clarity and consistency.]<br><br></li><li>The mapping of namespace URIs to prefixes SHOULD remain constant throughout the document, and SHOULD also be used in documentation of the design.&nbsp; [<i>Rationale: </i>Clarity and consistency.]<br><br></li><li>Well-known prefixes such as html: (for XHTML), dc: (for Dublin Core metadata), and xs: (for XML Schema) should be used for standard namespaces.&nbsp; [<i>Rationale:</i> Human readability.]<br><br></li><li>Redundant whitespace in a tag SHOULD NOT be
424*8c35d5eeSXin Liused.&nbsp; Use one space before each attribute in a start-tag; if the start
425*8c35d5eeSXin Litag is too long, the space MAY be replaced by a newline.&nbsp; [<i>Rationale:</i> Consistency and conciseness.]<br><br></li><li>Empty elements MAY be expressed as empty tags or a start-tag
426*8c35d5eeSXin Liimmediately followed by an end-tag. No distinction should be made
427*8c35d5eeSXin Libetween these two formats by any application.&nbsp; [<i>Rationale:</i> They are not distinguished by XML parsers.]<br><br></li><li>Documents MAY be pretty-printed using 2-space indentation for child
428*8c35d5eeSXin Lielements.&nbsp; Elements that contain character content SHOULD NOT be
429*8c35d5eeSXin Liwrapped.&nbsp; Long start-tags MAY be broken using newlines (possibly with extra indentation) after any attribute value except the last.&nbsp; [<i>Rationale:</i> General compatibility with our style.&nbsp; Wrapping character content affects its value.]<br><br></li><li>Attribute values MAY be surrounded with either quotation marks or apostrophes.
430*8c35d5eeSXin LiSpecifications MUST NOT require or forbid the use of either form.&nbsp; <span style="font-family: Courier New;">&amp;apos;</span> and <span style="font-family: Courier New;">&amp;quot;</span> may be freely used to escape each type of quote.&nbsp; [<i>Rationale:</i> No XML parsers report the distinction.]<br><br>
431*8c35d5eeSXin Li
432*8c35d5eeSXin Li</li><li>Comments MUST NOT be used to carry real data.&nbsp; Comments MAY be used to contain TODOs in hand-written XML.&nbsp; Comments SHOULD NOT be used at all in publicly transmitted documents. [<i>Rationale:&nbsp; </i>Comments are often discarded by parsers.]<br><br></li><li>If comments are nevertheless used, they SHOULD appear only in the document prolog or in elements that
433*8c35d5eeSXin Licontain child elements.&nbsp; If pretty-printing is required, pretty-print
434*8c35d5eeSXin Licomments like elements, but with line wrapping.&nbsp; Comments SHOULD NOT
435*8c35d5eeSXin Liappear in elements that contain character content.&nbsp; [<i>Rationale:&nbsp; </i>Whitespace in and around comments improves readability, but embedding a
436*8c35d5eeSXin Licomment in character content can lead to confusion about what
437*8c35d5eeSXin Liwhitespace is or is not in the content.]<br><br></li><li>Comments SHOULD have whitespace following <span style="font-family: Courier New;">&lt;!--</span> and preceding <span style="font-family: Courier New;">--&gt;</span>.&nbsp; [<i>Rationale:</i> Readability.]<br><br></li><li>CDATA sections MAY be used; they are equivalent to the use of <span style="font-family: Courier New;">&amp;amp;</span> and <span style="font-family: Courier New;">&amp;lt;</span>.&nbsp; Specifications MUST NOT require or forbid the use of CDATA sections.&nbsp; [<i>Rationale:</i> Few XML parsers report the distinction, and combinations of CDATA and text are often reported as single objects anyway.]<br><br></li><li>Entity references other than the XML standard entity references <span style="font-family: Courier New;">&amp;amp;</span>, <span style="font-family: Courier New;">&amp;lt;</span>, <span style="font-family: Courier New;">&amp;gt;</span>, <span style="font-family: Courier New;">&amp;quot;</span>, and <span style="font-family: Courier New;">&amp;apos;</span> MUST NOT be used.&nbsp; Character references MAY be used, but actual characters are preferred, unless the character encoding is not UTF-8.&nbsp; As usual, textual formats are exempt from this rule.<br></li></ol>
438*8c35d5eeSXin Li
439*8c35d5eeSXin Li<br><p>&nbsp;</p><p>
440*8c35d5eeSXin Li</p>
441*8c35d5eeSXin Li<p>
442*8c35d5eeSXin Li</p><br><br><h2>
443*8c35d5eeSXin Li12. Elements vs. Attributes
444*8c35d5eeSXin Li</h2>
445*8c35d5eeSXin Li<p>
446*8c35d5eeSXin Li<b>Note:</b>&nbsp; There are no hard and fast rules for deciding when to use attributes and when to use elements.&nbsp; Here are some of the considerations that designers should take into account; no rationales are given.
447*8c35d5eeSXin Li</p>
448*8c35d5eeSXin Li<h3>
449*8c35d5eeSXin Li12.1. General points:<br>
450*8c35d5eeSXin Li</h3>
451*8c35d5eeSXin Li
452*8c35d5eeSXin Li<ol>
453*8c35d5eeSXin Li<li>
454*8c35d5eeSXin Li<p>
455*8c35d5eeSXin LiAttributes are more restrictive than elements, and all designs have some elements, so an all-element design is simplest -- which is not the same as best.
456*8c35d5eeSXin Li</p>
457*8c35d5eeSXin Li<p>
458*8c35d5eeSXin Li<br>
459*8c35d5eeSXin Li</p>
460*8c35d5eeSXin Li</li>
461*8c35d5eeSXin Li<li>
462*8c35d5eeSXin Li<p>
463*8c35d5eeSXin LiIn a tree-style data model, elements are typically represented internally as nodes, which use more memory than the strings used to represent attributes.&nbsp; Sometimes the nodes are of different application-specific classes, which in many languages also takes up memory to represent the classes.
464*8c35d5eeSXin Li</p>
465*8c35d5eeSXin Li<p>
466*8c35d5eeSXin Li<br>
467*8c35d5eeSXin Li
468*8c35d5eeSXin Li</p>
469*8c35d5eeSXin Li</li>
470*8c35d5eeSXin Li<li>
471*8c35d5eeSXin Li<p>
472*8c35d5eeSXin LiWhen streaming, elements are processed one at a time (possibly even piece by piece, depending on the XML parser you are using), whereas all the attributes of an element and their values are reported at once, which costs memory, particularly if some attribute values are very long.
473*8c35d5eeSXin Li</p>
474*8c35d5eeSXin Li<p>
475*8c35d5eeSXin Li<br>
476*8c35d5eeSXin Li</p>
477*8c35d5eeSXin Li</li>
478*8c35d5eeSXin Li<li>
479*8c35d5eeSXin Li<p>
480*8c35d5eeSXin LiBoth element content and attribute values need to be escaped appropriately, so escaping should not be a consideration in the design.
481*8c35d5eeSXin Li</p>
482*8c35d5eeSXin Li<p>
483*8c35d5eeSXin Li<br>
484*8c35d5eeSXin Li</p>
485*8c35d5eeSXin Li
486*8c35d5eeSXin Li</li>
487*8c35d5eeSXin Li<li>
488*8c35d5eeSXin Li<p>
489*8c35d5eeSXin LiIn some programming languages and libraries, processing elements is easier; in others, processing attributes is easier.&nbsp; Beware of using ease of processing as a criterion.&nbsp; In particular, XSLT can handle either with equal facility.
490*8c35d5eeSXin Li</p>
491*8c35d5eeSXin Li<p>
492*8c35d5eeSXin Li<br>
493*8c35d5eeSXin Li</p>
494*8c35d5eeSXin Li</li>
495*8c35d5eeSXin Li<li>
496*8c35d5eeSXin Li<p>
497*8c35d5eeSXin LiIf a piece of data should usually be shown to the user, consider using an element; if not, consider using an attribute.&nbsp; (This rule is often violated for one reason or another.)
498*8c35d5eeSXin Li
499*8c35d5eeSXin Li</p>
500*8c35d5eeSXin Li<p>
501*8c35d5eeSXin Li<br>
502*8c35d5eeSXin Li</p>
503*8c35d5eeSXin Li</li>
504*8c35d5eeSXin Li<li>
505*8c35d5eeSXin Li<p>
506*8c35d5eeSXin LiIf you are extending an existing schema, do things by analogy to how things are done in that schema.
507*8c35d5eeSXin Li</p>
508*8c35d5eeSXin Li<p>
509*8c35d5eeSXin Li<br>
510*8c35d5eeSXin Li</p>
511*8c35d5eeSXin Li</li>
512*8c35d5eeSXin Li<li>
513*8c35d5eeSXin Li<p>
514*8c35d5eeSXin LiSensible schema languages, meaning RELAX NG and Schematron, treat elements and attributes symmetrically.&nbsp; Older and cruder<a href="https://www.w3.org/TR/2004/REC-xmlschema-0-20041028/" id="h2c3" title="XML Schema"> </a>schema languages such as DTDs and XML Schema, tend to have better support for elements.
515*8c35d5eeSXin Li
516*8c35d5eeSXin Li</p>
517*8c35d5eeSXin Li</li>
518*8c35d5eeSXin Li</ol>
519*8c35d5eeSXin Li<p>
520*8c35d5eeSXin Li</p>
521*8c35d5eeSXin Li<h3>
522*8c35d5eeSXin Li12.2 Using elements<br>
523*8c35d5eeSXin Li</h3>
524*8c35d5eeSXin Li<ol>
525*8c35d5eeSXin Li<li>
526*8c35d5eeSXin Li<p>
527*8c35d5eeSXin LiIf something might appear more than once in a data model, use an element rather than introducing attributes with names like <span style="font-family: Courier New;">foo1, foo2, foo3</span> ....
528*8c35d5eeSXin Li</p>
529*8c35d5eeSXin Li
530*8c35d5eeSXin Li<p>
531*8c35d5eeSXin Li<br>
532*8c35d5eeSXin Li</p>
533*8c35d5eeSXin Li</li>
534*8c35d5eeSXin Li<li>
535*8c35d5eeSXin Li<p>
536*8c35d5eeSXin LiUse elements to represent a piece of information that can be considered an independent object and when the information is related via a parent/child relationship to another piece of information.
537*8c35d5eeSXin Li</p>
538*8c35d5eeSXin Li<p>
539*8c35d5eeSXin Li<br>
540*8c35d5eeSXin Li</p>
541*8c35d5eeSXin Li</li>
542*8c35d5eeSXin Li<li>
543*8c35d5eeSXin Li<p>
544*8c35d5eeSXin LiUse elements when data incorporates strict typing or relationship rules.
545*8c35d5eeSXin Li</p>
546*8c35d5eeSXin Li<p>
547*8c35d5eeSXin Li
548*8c35d5eeSXin Li<br>
549*8c35d5eeSXin Li</p>
550*8c35d5eeSXin Li</li>
551*8c35d5eeSXin Li<li>
552*8c35d5eeSXin Li<p>
553*8c35d5eeSXin LiIf order matters between two pieces of data, use elements for them: attributes are inherently unordered.
554*8c35d5eeSXin Li</p>
555*8c35d5eeSXin Li<p>
556*8c35d5eeSXin Li<br>
557*8c35d5eeSXin Li</p>
558*8c35d5eeSXin Li</li>
559*8c35d5eeSXin Li<li>
560*8c35d5eeSXin Li<p>
561*8c35d5eeSXin LiIf a piece of data has, or might have, its own substructure, use it in an element: getting substructure into an attribute is always messy.&nbsp; Similarly, if the data is a constituent part of some larger piece of data, put it in an element.
562*8c35d5eeSXin Li</p>
563*8c35d5eeSXin Li
564*8c35d5eeSXin Li<p>
565*8c35d5eeSXin Li<br>
566*8c35d5eeSXin Li</p>
567*8c35d5eeSXin Li</li>
568*8c35d5eeSXin Li<li>
569*8c35d5eeSXin Li<p>
570*8c35d5eeSXin LiAn exception to the previous rule: multiple whitespace-separated tokens can safely be put in an attribute.&nbsp; In principle, the separator can be anything, but schema-language validators are currently only able to handle whitespace, so it's best to stick with that.
571*8c35d5eeSXin Li</p>
572*8c35d5eeSXin Li<p>
573*8c35d5eeSXin Li<br>
574*8c35d5eeSXin Li</p>
575*8c35d5eeSXin Li</li>
576*8c35d5eeSXin Li<li>
577*8c35d5eeSXin Li<p>
578*8c35d5eeSXin LiIf a piece of data extends across multiple lines, use an element: XML parsers will change newlines in attribute values into spaces.
579*8c35d5eeSXin Li
580*8c35d5eeSXin Li<br><br></p></li><li>If a piece of data is very large, use an element so that its content can be streamed.<br><br></li>
581*8c35d5eeSXin Li<li>
582*8c35d5eeSXin Li<p>
583*8c35d5eeSXin LiIf a piece of data is in a natural language, put it in an element so you can use the <span style="font-family: Courier New;">xml:lang</span> attribute to label the language being used.&nbsp; Some kinds of natural-language text, like Japanese, often make use <a href="https://www.w3.org/TR/2001/REC-ruby-20010531" id="pa2f" title="annotations">annotations</a> that are conventionally represented using child elements; right-to-left languages like Hebrew and Arabic may similarly require child elements to manage <a href="https://www.w3.org/TR/2001/REC-ruby-20010531" id="ehyv" title="bidirectionality">bidirectionality</a> properly.
584*8c35d5eeSXin Li</p>
585*8c35d5eeSXin Li
586*8c35d5eeSXin Li<p>
587*8c35d5eeSXin Li</p>
588*8c35d5eeSXin Li</li>
589*8c35d5eeSXin Li</ol>
590*8c35d5eeSXin Li<h3>
591*8c35d5eeSXin Li12.3 Using attributes<br>
592*8c35d5eeSXin Li</h3>
593*8c35d5eeSXin Li<ol>
594*8c35d5eeSXin Li<li>
595*8c35d5eeSXin Li<p>
596*8c35d5eeSXin LiIf the data is a code from an enumeration, code list, or controlled vocabulary, put it in an attribute if possible.&nbsp; For example, language tags, currency codes, medical diagnostic codes, etc. are best handled as attributes.
597*8c35d5eeSXin Li</p>
598*8c35d5eeSXin Li<p>
599*8c35d5eeSXin Li<br>
600*8c35d5eeSXin Li
601*8c35d5eeSXin Li</p>
602*8c35d5eeSXin Li</li>
603*8c35d5eeSXin Li<li>
604*8c35d5eeSXin Li<p>
605*8c35d5eeSXin LiIf a piece of data is really metadata on some other piece of data (for example, representing a class or role that the main data serves,&nbsp; or specifying a method of processing it), put it in an attribute if possible.
606*8c35d5eeSXin Li</p>
607*8c35d5eeSXin Li<p>
608*8c35d5eeSXin Li<br>
609*8c35d5eeSXin Li</p>
610*8c35d5eeSXin Li</li>
611*8c35d5eeSXin Li<li>
612*8c35d5eeSXin Li<p>
613*8c35d5eeSXin LiIn particular, if a piece of data is an ID for some other piece of data, or a reference to such an ID, put the identifying piece in an attribute.&nbsp; When it's an ID, use the name <span style="font-family: Courier New;">xml:id</span> for the attribute.
614*8c35d5eeSXin Li
615*8c35d5eeSXin Li</p>
616*8c35d5eeSXin Li<p>
617*8c35d5eeSXin Li<br>
618*8c35d5eeSXin Li</p>
619*8c35d5eeSXin Li</li>
620*8c35d5eeSXin Li<li>
621*8c35d5eeSXin Li<p>
622*8c35d5eeSXin LiHypertext references are conventionally put in <span style="font-family: Courier New;">href</span> attributes.
623*8c35d5eeSXin Li</p>
624*8c35d5eeSXin Li<p>
625*8c35d5eeSXin Li<br>
626*8c35d5eeSXin Li</p>
627*8c35d5eeSXin Li</li>
628*8c35d5eeSXin Li<li>
629*8c35d5eeSXin Li
630*8c35d5eeSXin Li<p>
631*8c35d5eeSXin LiIf a piece of data is applicable to an element and any descendant elements unless it is overridden in some of them, it is conventional to put it in an attribute.&nbsp; Well-known examples are <span style="font-family: Courier New;">xml:lang</span>, <span style="font-family: Courier New;">xml:space</span>, <span style="font-family: Courier New;">xml:base</span>, and namespace declarations.
632*8c35d5eeSXin Li</p>
633*8c35d5eeSXin Li<p>
634*8c35d5eeSXin Li<br>
635*8c35d5eeSXin Li</p>
636*8c35d5eeSXin Li</li>
637*8c35d5eeSXin Li<li>
638*8c35d5eeSXin Li<p>
639*8c35d5eeSXin Li
640*8c35d5eeSXin LiIf terseness is really the <i>most</i> important thing, use attributes, but consider <span style="font-family: Courier New;">gzip</span> compression instead -- it works very well on documents with highly repetitive structures.</p></li>
641*8c35d5eeSXin Li</ol></div><br><div><div><div><div><div>
642*8c35d5eeSXin Li<br><h2>13. Parting words
643*8c35d5eeSXin Li</h2>
644*8c35d5eeSXin Li<p>
645*8c35d5eeSXin Li</p><p>
646*8c35d5eeSXin LiUse common sense and <i>BE CONSISTENT</i>.&nbsp;&nbsp; Design for extensibility.&nbsp; You <i>are</i> gonna need it.&nbsp; [<i>Rationale:</i> Long and painful experience.]<br></p><p><br> </p>
647*8c35d5eeSXin Li
648*8c35d5eeSXin Li<p>
649*8c35d5eeSXin LiWhen designing XML formats, take a few minutes to look at other formats and determine their style.&nbsp; The point of having style guidelines is so that people can concentrate on what you are
650*8c35d5eeSXin Lisaying, rather than on how you are saying it. <br></p><p>
651*8c35d5eeSXin Li<br>
652*8c35d5eeSXin LiBreak <i>ANY OR ALL</i> of these rules (yes, even the ones that say MUST) rather than create a crude, arbitrary, disgusting mess of a design if that's what following them slavishly would give you.&nbsp; In particular, random mixtures of attributes and child elements are hard to follow and hard to use, though it often makes good sense to use both when the data clearly fall into two different groups such as simple/complex or metadata/data.
653*8c35d5eeSXin Li</p>
654*8c35d5eeSXin Li<div><p>
655*8c35d5eeSXin Li<br>
656*8c35d5eeSXin LiNewbies always ask:
657*8c35d5eeSXin Li</p>
658*8c35d5eeSXin Li
659*8c35d5eeSXin Li<p>
660*8c35d5eeSXin Li&nbsp;&nbsp;&nbsp; "Elements or attributes?
661*8c35d5eeSXin Li</p>
662*8c35d5eeSXin Li<p>
663*8c35d5eeSXin LiWhich will serve me best?"
664*8c35d5eeSXin Li</p>
665*8c35d5eeSXin Li<p>
666*8c35d5eeSXin Li&nbsp;&nbsp;&nbsp; Those who know roar like lions;
667*8c35d5eeSXin Li</p>
668*8c35d5eeSXin Li<p>
669*8c35d5eeSXin Li&nbsp;&nbsp;&nbsp; Wise hackers smile like tigers.
670*8c35d5eeSXin Li</p>
671*8c35d5eeSXin Li<p>
672*8c35d5eeSXin Li&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; --a <a href="https://en.wikipedia.org/wiki/Waka_%28poetry%29#Forms_of_waka" id="s3k3" title="tanka">tanka</a>, or extended haiku
673*8c35d5eeSXin Li
674*8c35d5eeSXin Li</p>
675*8c35d5eeSXin Li</div>
676*8c35d5eeSXin Li<p>
677*8c35d5eeSXin Li<br>
678*8c35d5eeSXin Li</p>
679*8c35d5eeSXin Li<br>[TODO: if a registry of schemas is set up, add a link to it]<br><br></div><br></div><br></div></div></div><br>
680*8c35d5eeSXin Li<br clear="all"/>
681*8c35d5eeSXin Li</div>
682