⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 introxml2.html

📁 j2eePDF格式的电子书
💻 HTML
📖 第 1 页 / 共 3 页
字号:
</pre></div><hr><a name="wp63911"> </a><p class="pNote">Note: The empty tag saves you from having to code <code class="cCode">&lt;flag&gt;&lt;/flag&gt;</code> in order to have a well-formed document. You can control which tags are allowed to be empty by creating a Document Type Definition, or <a  href="IntroXML3.html#wp64130">DTD</a>. We'll talk about that in a few moments. If there is no DTD, then the document can contain any kinds of tags you want, as long as the document is well-formed. </p><hr><a name="wp63916"> </a><h4 class="pHeading3">Comments in XML Files</h4><a name="wp63917"> </a><p class="pBody">XML comments look just like HTML comments:</p><div class="pPreformattedRelative"><pre class="pPreformattedRelative">&lt;message to=&quot;you@yourAddress.com&quot; from=&quot;me@myAddress.com&quot; &nbsp;&nbsp;&nbsp;&nbsp;subject=&quot;XML Is Really Cool&quot;&gt;<span style="font-weight: bold">&nbsp;&nbsp;&lt;!-- This is a comment --&gt;</span>&nbsp;&nbsp;&lt;text&gt;&nbsp;&nbsp;&nbsp;&nbsp;How many ways is XML cool? Let me count the ways...&nbsp;&nbsp;&lt;/text&gt;&lt;/message&gt;<a name="wp63918"> </a></pre></div><a name="wp63920"> </a><h4 class="pHeading3">The XML Prolog</h4><a name="wp63921"> </a><p class="pBody">To complete this journeyman's introduction to XML, note that an XML file always starts with a prolog. The minimal prolog contains a declaration that identifies the document as an XML document, like this:</p><div class="pPreformattedRelative"><pre class="pPreformattedRelative">&lt;?xml version=&quot;1.0&quot;?&gt;<a name="wp63922"> </a></pre></div><a name="wp63923"> </a><p class="pBody">The declaration may also contain additional information, like this:</p><div class="pPreformattedRelative"><pre class="pPreformattedRelative">&lt;?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot; standalone=&quot;yes&quot;?&gt;<a name="wp63924"> </a></pre></div><a name="wp63925"> </a><p class="pBody">The XML declaration is essentially the same as the HTML header, <code class="cCode">&lt;html&gt;</code>, except that it uses <code class="cCode">&lt;?..?&gt;</code> and it may contain the following attributes:</p><a name="wp63926"> </a><p class="pDefinitionTerm">version</p><a name="wp63927"> </a><p class="pDefinition">Identifies the version of the XML markup language used in the data. This attribute is not optional.</p><a name="wp63928"> </a><p class="pDefinitionTerm">encoding</p><a name="wp63929"> </a><p class="pDefinition">Identifies the character set used to encode the data. &quot;ISO-8859-1&quot; is &quot;Latin-1&quot; the Western European and English language character set. (The default is compressed Unicode: UTF-8.)</p><a name="wp63930"> </a><p class="pDefinitionTerm">standalone</p><a name="wp63931"> </a><p class="pDefinition">Tells whether or not this document references an external entity or an external data type specification (see below). If there are no external references, then &quot;yes&quot; is appropriate</p><a name="wp63932"> </a><p class="pBody">The prolog can also contain definitions of entities (items that are inserted when you reference them from within the document) and specifications that tell which tags are valid in the document, both declared in a Document Type Definition (<a  href="IntroXML3.html#wp64130">DTD</a>) that can be defined directly within the prolog, as well as with pointers to external specification files. But those are the subject of later tutorials. For more information on these and many other aspects of XML, see the Recommended Reading list of the w3c XML page at <code class="cCode"><a  href="http://www.w3.org/XML/" target="_blank">http://www.w3.org/XML/</a></code>.</p><hr><a name="wp63936"> </a><p class="pNote">Note: The declaration is actually optional. But it's a good idea to include it whenever you create an XML file. The declaration should have the version number, at a minimum, and ideally the encoding as well. That standard simplifies things if the XML standard is extended in the future, and if the data ever needs to be localized for different geographical regions.</p><hr><a name="wp63937"> </a><p class="pBody">Everything that comes after the XML prolog constitutes the document's <span style="font-style: italic">content</span>.</p><a name="wp63939"> </a><h4 class="pHeading3">Processing Instructions</h4><a name="wp63940"> </a><p class="pBody">An XML file can also contain <span style="font-style: italic">processing instructions</span> that give commands or information to an application that is processing the XML data. Processing instructions have the following format:</p><div class="pPreformattedRelative"><pre class="pPreformattedRelative">  &lt;?<span style="font-style: oblique; font-weight: bold">target</span><span style="font-style: normal; font-weight: bold"> </span><span style="font-style: oblique; font-weight: bold">instructions</span>?&gt;<a name="wp63941"> </a></pre></div><a name="wp63942"> </a><p class="pBody">where the <span style="font-style: italic">target</span> is the name of the application that is expected to do the processing, and <span style="font-style: italic">instructions</span> is a string of characters that embodies the information or commands for the application to process.</p><a name="wp63943"> </a><p class="pBody">Since the instructions are application specific, an XML file could have multiple processing instructions that tell different applications to do similar things, though in different ways. The XML file for a slideshow, for example, could have processing instructions that let the speaker specify a technical or executive-level version of the presentation. If multiple presentation programs were used, the program might need multiple versions of the processing instructions (although it would be nicer if such applications recognized standard instructions).</p><hr><a name="wp63944"> </a><p class="pNote">Note: The target name &quot;xml&quot; (in any combination of upper or lowercase letters) is reserved for XML standards. In one sense, the declaration is a processing instruction that fits that standard. (However, when you're working with the parser later, you'll see that the method for handling processing instructions never sees the declaration.)</p><hr><a name="wp63946"> </a><h3 class="pHeading2">Why Is XML Important?</h3><a name="wp63947"> </a><p class="pBody">There are a number of reasons for XML's surging acceptance. This section lists a few of the most prominent.</p><a name="wp63948"> </a><h4 class="pHeading3">Plain Text</h4><a name="wp63949"> </a><p class="pBody">Since XML is not a binary format, you can create and edit files with anything from a standard text editor to a visual development environment. That makes it easy to debug your programs, and makes it useful for storing small amounts of data. At the other end of the spectrum, an XML front end to a database makes it possible to efficiently store large amounts of XML data as well. So XML provides scalability for anything from small configuration files to a company-wide data repository.</p><a name="wp63950"> </a><h4 class="pHeading3">Data Identification</h4><a name="wp63951"> </a><p class="pBody">XML tells you what kind of data you have, not how to display it. Because the markup tags identify the information and break up the data into parts, an email program can process it, a search program can look for messages sent to particular people, and an address book can extract the address information from the rest of the message. In short, because the different parts of the information have been identified, they can be used in different ways by different applications.</p><a name="wp63953"> </a><h4 class="pHeading3">Stylability</h4><a name="wp63957"> </a><p class="pBody">When display is important, the stylesheet standard, <a  href="IntroXML3.html#wp64148">XSL</a>, lets you dictate how to portray the data. For example, the stylesheet for:</p><div class="pPreformattedRelative"><pre class="pPreformattedRelative">&lt;to&gt;you@yourAddress.com&lt;/to&gt;<a name="wp63958"> </a></pre></div><a name="wp63959"> </a><p class="pBody">can say:</p><div class="pSmartList1"><ol type="1" class="pSmartList1"><a name="wp63960"> </a><div class="pSmartList1"><li>Start a new line.</li></div><a name="wp63961"> </a><div class="pSmartList1"><li>Display &quot;To:&quot; in bold, followed by a space</li></div><a name="wp63962"> </a><div class="pSmartList1"><li>Display the destination data.</li></div></ol></div><a name="wp63963"> </a><p class="pBody">Which produces:</p><div class="pPreformattedRelative"><pre class="pPreformattedRelative"><span style="font-weight: bold">To: </span>you@yourAddress<a name="wp63964"> </a></pre></div><a name="wp63965"> </a><p class="pBody">Of course, you could have done the same thing in HTML, but you wouldn't be able to process the data with search programs and address-extraction programs and the like. More importantly, since XML is inherently style-free, you can use a completely different stylesheet to produce output in postscript, TEX, PDF, or some new format that hasn't even been invented yet. That flexibility amounts to what one author described as &quot;future-proofing&quot; your information. The XML documents you author today can be used in future document-delivery systems that haven't even been imagined yet.</p><a name="wp63967"> </a><h4 class="pHeading3">Inline Reusability</h4>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -