XML.xhtml 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <!--
  3. h t t :: / / t /
  4. h t t :: // // t //
  5. h ttttt ttttt ppppp sssss // // y y sssss ttttt //
  6. hhhh t t p p s // // y y s t //
  7. h hh t t ppppp sssss // // yyyyy sssss t //
  8. h h t t p s :: / / y .. s t .. /
  9. h h t t p sssss :: / / yyyyy .. sssss t .. /
  10. <https://y.st./>
  11. Copyright © 2017 Alex Yst <mailto:copyright@y.st>
  12. This program is free software: you can redistribute it and/or modify
  13. it under the terms of the GNU General Public License as published by
  14. the Free Software Foundation, either version 3 of the License, or
  15. (at your option) any later version.
  16. This program is distributed in the hope that it will be useful,
  17. but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. GNU General Public License for more details.
  20. You should have received a copy of the GNU General Public License
  21. along with this program. If not, see <https://www.gnu.org./licenses/>.
  22. -->
  23. <!DOCTYPE html>
  24. <html xmlns="http://www.w3.org/1999/xhtml">
  25. <head>
  26. <base href="https://y.st./en/opinion/XML.xhtml" />
  27. <title>XML &lt;https://y.st./en/opinion/XML.xhtml&gt;</title>
  28. <link rel="icon" type="image/png" href="/link/CC_BY-SA_4.0/y.st./icon.png" />
  29. <link rel="stylesheet" type="text/css" href="/link/basic.css" />
  30. <link rel="stylesheet" type="text/css" href="/link/site-specific.css" />
  31. <script type="text/javascript" src="/script/javascript.js" />
  32. <meta name="viewport" content="width=device-width" />
  33. </head>
  34. <body>
  35. <nav>
  36. <p>
  37. <a href="/en/">Home</a> |
  38. <a href="/en/a/about.xhtml">About</a> |
  39. <a href="/en/a/contact.xhtml">Contact</a> |
  40. <a href="/a/canary.txt">Canary</a> |
  41. <a href="/en/URI_research/"><abbr title="Uniform Resource Identifier">URI</abbr> research</a> |
  42. <a href="/en/opinion/">Opinions</a> |
  43. <a href="/en/coursework/">Coursework</a> |
  44. <a href="/en/law/">Law</a> |
  45. <a href="/en/a/links.xhtml">Links</a> |
  46. <a href="/en/opinion/XML.xhtml.asc">{this page}.asc</a>
  47. </p>
  48. <hr/>
  49. <p>
  50. <a href="/en/opinion/XML.xhtml"><abbr title="Extensible Markup Language">XML</abbr></a> |
  51. <a href="/en/opinion/code_indentation.xhtml">Code indentation</a> |
  52. <a href="/en/opinion/free_culture.xhtml">Free culture</a> |
  53. <a href="/en/opinion/free_software.xhtml">Free software</a> |
  54. <a href="/en/opinion/holidays.xhtml">Holidays</a> |
  55. <a href="/en/opinion/misuse_of_words.xhtml">Misuse of words</a>
  56. </p>
  57. <hr/>
  58. </nav>
  59. <header>
  60. <h1><abbr title="Extensible Markup Language">XML</abbr></h1>
  61. <p>Extensible Markup Language</p>
  62. </header>
  63. <h2>Cleaner than <abbr title="Hypertext Markup Language">HTML</abbr></h2>
  64. <p>
  65. <abbr title="Extensible Markup Language">XML</abbr>&apos;s greatest strength is that unlike <abbr title="Hypertext Markup Language">HTML</abbr>, it must be valid to be rendered.
  66. Rendering malformed files by default isn&apos;t the best idea.
  67. With <abbr title="Extensible Markup Language">XML</abbr>, when you check out how your code looks, you can immediately see when your code&apos;s malformed so you can fix it.
  68. In <abbr title="Hypertext Markup Language">HTML</abbr>, such errors are often glossed over by the Web browser so you don&apos;t even see them.
  69. Before the <abbr title="Web Hypertext Application Technology Working Group">WHATWG</abbr> formed and got involved, there was another important reason to use <abbr title="Extensible Markup Language">XML</abbr> as well: mobile clients.
  70. Fixing malformed markup in order to render it takes electrical power and processing power, both things that are in shorter supply on mobile clients.
  71. Had the Web moved forward with <abbr title="Extensible Hypertext Markup Language">XHTML</abbr>2 and <abbr title="Hypertext Markup Language">HTML</abbr> been discontinued, mobile clients wouldn&apos;t have to have been made to interpret bad markup.
  72. They could rely on markup to be clean, and if it wasn&apos;t, they could display the same error message that would be displayed on a desktop client.
  73. Thanks to the <abbr title="Web Hypertext Application Technology Working Group">WHATWG</abbr> though, <abbr title="Hypertext Markup Language">HTML</abbr> is continuing forward, despite its glaring flaws, and mobile clients will likely always spend their limited resources on cleaning up broken pages internally before rendering them.
  74. </p>
  75. <h2>Escape your code properly</h2>
  76. <p>
  77. Please don&apos;t be a lazy bastard.
  78. Don&apos;t use <code>&lt;![CDATA[</code> <code>]]&gt;</code> in your code.
  79. There are exactly zero cases in which this construct is needed.
  80. All that this construct does is allow you to be lazy and neglect to escape your <code>&lt;</code>, <code>&gt;</code>, and <code>&amp;</code> characters.
  81. I&apos;m not entirely certain, but it&apos;s possible that it also functions in some cases in which <code>&quot;</code> or <code>&apos;</code> could need to be escaped.
  82. However, you should strive to write clean code.
  83. Simply escape your characters properly, and you won&apos;t have any issues.
  84. Escaping your characters properly even works within <code>&lt;script/&gt;</code> and <code>&lt;style/&gt;</code> tags; it doesn&apos;t interfere with the interpretation of JavaScript or <abbr title="Cascading Style Sheets">CSS</abbr>.
  85. That said, you shouldn&apos;t have JavaScript or <abbr title="Cascading Style Sheets">CSS</abbr> in the same file as your <abbr title="Extensible Hypertext Markup Language">XHTML</abbr> in most cases.
  86. In all but a few corner cases, JavaScript and <abbr title="Cascading Style Sheets">CSS</abbr> should be stored in external files and linked to by the <abbr title="Extensible Hypertext Markup Language">XHTML</abbr> file.
  87. </p>
  88. <h2>Criticism of <abbr title="Extensible Markup Language">XML</abbr></h2>
  89. <p>
  90. Most of the criticism that I hear about <abbr title="Extensible Markup Language">XML</abbr> falls into one of three categories.
  91. </p>
  92. <h3><abbr title="Hypertext Markup Language">HTML</abbr> allows broken code</h3>
  93. <p>
  94. It used to be that when an <abbr title="Hypertext Markup Language">HTML</abbr> page was malformed, Web browsers wouldn&apos;t be able to render it.
  95. This was like any other file; when it&apos;s malformed, it doesn&apos;t make any sense to the renderer.
  96. However, back when competition between Web browser vendors was more fierce, Web browser venders started adding the ability to render malformed markup.
  97. In this way, Web developers that used those Web browsers wouldn&apos;t notice mistakes in their code, so those mistakes didn&apos;t get fixed.
  98. Other Web browsers that hadn&apos;t yet added the ability to render malformed documents weren&apos;t able to display these pages, and users blamed the Web browsers that conformed to the standard instead of those that had caused it: the Web browsers that <strong>*didn&apos;t*</strong> conform to the standard.
  99. The rendering of invalid <abbr title="Hypertext Markup Language">HTML</abbr> is a horrid artifact of a past war between software developers.
  100. It&apos;s not a good thing, but a blemish on the entire Web.
  101. If you try using the <abbr title="World Wide Web Consortium">W3C</abbr> validator on most Web pages, you&apos;ll find that even those developed by the most professional of companies often aren&apos;t even valid pages.
  102. Being able to see your page break and know to fix it is a <strong>*very good thing*</strong>, which is a big part of why we need <abbr title="Extensible Markup Language">XML</abbr>.
  103. </p>
  104. <h3><abbr title="Hypertext Markup Language">HTML</abbr> allows missing tags</h3>
  105. <p>
  106. Some people claim that omitting close tags is somehow cleaner because it&apos;s less verbose in some cases.
  107. <abbr title="Hypertext Markup Language">HTML</abbr>5 allows that practice in many cases.
  108. However, is that really cleaner?
  109. You&apos;re not telling the parser where your element stops.
  110. Instead, you&apos;re relying on the parser to end your element when another begins or when it finds itself unable to continue the element for some reason, such as when the container element ends.
  111. Omitting useful information isn&apos;t the way to write clean code.
  112. Leaving out closing tags is about as clean as leaving out closing parentheses.
  113. </p>
  114. <blockquote>
  115. <p>
  116. Does this look very clean to you?
  117. (It&apos;s shorter, but that doesn&apos;t make it cleaner.
  118. </p>
  119. </blockquote>
  120. <p>
  121. As a side note, <abbr title="Extensible Markup Language">XML</abbr> also has a neat feature in which single tags look different than open tags.
  122. You might not find that useful if you know all of the tags available in your markup language, but often times, you know the subset of tags that you actually use or that you use most often.
  123. When looking at <abbr title="Extensible Markup Language">XML</abbr>, you know when a tag you don&apos;t recognize is open or is a single tag with no close tag.
  124. You can even self-close empty tags.
  125. For example, I write <code>&lt;script src=&quot;/script/javascript.js&quot; /&gt;</code> instead of <code>&lt;script src=&quot;/script/javascript.js&quot;&gt;&lt;/script&gt;</code>.
  126. In <abbr title="Hypertext Markup Language">HTML</abbr>, there&apos;s no way to condense this, and you must always specify a close tag even when it makes no sense for the element to even be open.
  127. Otherwise, the entire rest of the page might be interpreted as malformed JavaScript instead of as <abbr title="Hypertext Markup Language">HTML</abbr>.
  128. </p>
  129. <h3><abbr title="JavaScript Object Notation">JSON</abbr> (or something else) is better for storing data</h3>
  130. <p>
  131. <abbr title="Extensible Markup Language">XML</abbr> isn&apos;t a data-storage format.
  132. It&apos;s a document markup format. It&apos;s Extensible Markup Language, after all, not Extensible Data-Storage Language.
  133. If you misuse a tool, sure, you&apos;ll get poor performance out of it.
  134. For example, if you store textual information as a <abbr title="Portable Network Graphic">PNG</abbr> file and claim that that&apos;s what <abbr title="Portable Network Graphic">PNG</abbr> files are for, it&apos;s going to make the <abbr title="Portable Network Graphic">PNG</abbr> format look bad.
  135. <abbr title="Portable Network Graphic">PNG</abbr> files are absolutely horrid for storing textual information.
  136. However, they excel at storing non-photographic graphic art.
  137. The same applies to <abbr title="Extensible Markup Language">XML</abbr>.
  138. If you try to use <abbr title="Extensible Markup Language">XML</abbr> as a data-storage format, you&apos;re going to get suboptimal results.
  139. If you&apos;re storing data, yes, <abbr title="JavaScript Object Notation">JSON</abbr> is the better format!
  140. However, it&apos;s not because <abbr title="JavaScript Object Notation">JSON</abbr> is actually a better format than <abbr title="Extensible Markup Language">XML</abbr> at all.
  141. It&apos;s because <abbr title="JavaScript Object Notation">JSON</abbr>&apos;s strength is data storage while <abbr title="Extensible Markup Language">XML</abbr>&apos;s strength is instead document markup.
  142. </p>
  143. <h4><abbr title="Extensible Markup Language">XML</abbr> for data storage</h4>
  144. <p>
  145. As I said, <abbr title="Extensible Markup Language">XML</abbr> is a markup language, not a data-storage language.
  146. However, it can still be used effectively for data storage when used correctly.
  147. Much of the problem when developing an <abbr title="Extensible Markup Language">XML</abbr> flavor for data storage that makes it inefficient is caused by people doing it wrong.
  148. Again, this isn&apos;t the fault of <abbr title="Extensible Markup Language">XML</abbr> and doesn&apos;t mean that <abbr title="Extensible Markup Language">XML</abbr> itself isn&apos;t good for what it&apos;s good at.
  149. Instead of having an element for each key/value pair, it&apos;s often more efficient to instead use attributes of a single element.
  150. According to Wikipedia, doing that <a href="https://en.wikipedia.org./wiki/JSON#XML">results in file sizes that are just as small or only slightly larger than those achieved in <abbr title="JavaScript Object Notation">JSON</abbr></a>.
  151. Even when <abbr title="Extensible Markup Language">XML</abbr> is the wrong tool for the job, it does pretty well when used with a little skill.
  152. Now that&apos;s impressive!
  153. Additionally, in <abbr title="Extensible Markup Language">XML</abbr>, you can see what element is ending when it ends.
  154. In <abbr title="JavaScript Object Notation">JSON</abbr>, you can&apos;t do that.
  155. Instead, you have to count your layered braces to find the start of the nested element to know what element it is.
  156. Proper indention of course helps with this, but it helps in <abbr title="Extensible Markup Language">XML</abbr> too.
  157. </p>
  158. <hr/>
  159. <p>
  160. Copyright © 2017 Alex Yst;
  161. You may modify and/or redistribute this document under the terms of the <a rel="license" href="/license/gpl-3.0-standalone.xhtml"><abbr title="GNU&apos;s Not Unix">GNU</abbr> <abbr title="General Public License version Three or later">GPLv3+</abbr></a>.
  162. If for some reason you would prefer to modify and/or distribute this document under other free copyleft terms, please ask me via email.
  163. My address is in the source comments near the top of this document.
  164. This license also applies to embedded content such as images.
  165. For more information on that, see <a href="/en/a/licensing.xhtml">licensing</a>.
  166. </p>
  167. <p>
  168. <abbr title="World Wide Web Consortium">W3C</abbr> standards are important.
  169. This document conforms to the <a href="https://validator.w3.org./nu/?doc=https%3A%2F%2Fy.st.%2Fen%2Fopinion%2FXML.xhtml"><abbr title="Extensible Hypertext Markup Language">XHTML</abbr> 5.1</a> specification and uses style sheets that conform to the <a href="http://jigsaw.w3.org./css-validator/validator?uri=https%3A%2F%2Fy.st.%2Fen%2Fopinion%2FXML.xhtml"><abbr title="Cascading Style Sheets">CSS</abbr>3</a> specification.
  170. </p>
  171. </body>
  172. </html>