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

📄 1_xml.html

📁 XML_JAVA指南 书籍语言: 简体中文 书籍类型: 程序设计 授权方式: 免费软件 书籍大小: 377 KB
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"><!--NewPage--><html><head><title>A Quick Introduction to XML</title><style type="text/css"><!----></style><meta name="fileID" content="quickIntro"><meta name="keywords" content="XML"></head><body BGCOLOR="#ffffff"><table width="100%"><tr>    <td align=left> <a href="index.html"><img src="../images/PreviousArrow.gif" width=26 height=26 align=bottom border=0 alt="Previous | "></a><ahref="2_specs.html"><img src="../images/NextArrow.gif" width=26 height=26 align=bottom border=0 alt="Next | "></a><a href="../alphaIndex.html"><img src="../images/xml_IDX.gif" width=26 height=26 align=bottom border=0 alt="Index | "></a><a href="../TOC.html"><imgsrc="../images/xml_TOC.gif" width=26 height=26 align=bottom border=0 alt="TOC | "></a><a href="../index.html"><imgsrc="../images/xml_Top.gif" width=26 height=26 align=bottom border=0 alt="Top | "></a>     </td>    <td align=right><strong><em><a href="index.html">Top</a></em></strong> <a href="../TOC.html#intro"><strong><em></em></strong></a> <a href="../TOC.html#intro"><strong><em>Contents</em></strong></a>       <a href="../alphaIndex.html"><strong><em>Index</em></strong></a> <a href="../glossary.html"><strong><em>Glossary</em></strong></a></td></tr></table><p><center>    <IMG SRC="../images/shoeline2.gif" ALIGN="BOTTOM" BORDER="0" WIDTH="202"    HEIGHT="25" NATURALSIZEFLAG="3"> <IMG SRC="../images/shoeline2.gif" ALIGN="BOTTOM" BORDER="0" WIDTH="202"    HEIGHT="25" NATURALSIZEFLAG="3">   </center>  <blockquote>      <blockquote>         <hr size=4>     </blockquote>  </blockquote><p> <h2> 1. A Quick Introduction to XML</h2><table width="40%" border="1" align="right">  <tr>     <td>       <div align="center"><b><i>Link Summary</i></b></div>    </td>  </tr>  <tr>     <td>       <dl>         <dt><b><i>Local Links</i></b></dt>      </dl>      <ul>        <li><a href="2_specs.html">XML and Related Specs</a></li>        <li><a href="4_design.html">Designing an XML Data Structure</a></li>        <li><a href="2_specs.html#RDF">RDF</a></li>        <li><a href="2_specs.html#XSL">XSL</a><br>        </li>      </ul>      <dl>         <dt><i><b>External Links</b></i> </dt>      </dl>      <ul>        <li><a href="http://www.ucc.ie/xml/">XML FAQ</a></li>        <li><a href="http://www.w3.org/XML/">XML Info and Recommended Reading</a></li>        <li><a href="http://www.oasis-open.org/cover/">SGML/XML Web Page</a></li>        <li><a href="http://www.sciam.com/1999/0599issue/0599bosak.html">Scientific           American article</a></li>      </ul>      <dl>         <dt><b><i>Glossary Terms</i></b></dt>        <dd><a href="../glossary.html#attribute">attributes</a>, <a href="../glossary.html#declaration">declaration</a>,           <a href="2_specs.html#DTD">DTD</a>, <a href="../glossary.html#element">element</a>,           <a href="../glossary.html#entity">entity</a>, <a href="../glossary.html#prolog">prolog</a>,           <a href="../glossary.html#tag">tag</a>, <a href="../glossary.html#wellFormed">well-formed</a>         </dd>      </dl>    </td>  </tr></table><p> This page covers the basics of XML. The goal is to give you just enough information   to get started, so you understand what XML is all about. (You'll learn about   XML in later sections of the tutorial.) We then outline the major features that   make XML great for information storage and interchange, and give you a general   idea of how XML can be used. This section of the tutorial covers: <ul>  <li> <a href="#intro">What Is XML?</a> </li>  <li> <a href="#cool">Why Is XML Important?</a> </li>  <li><a href="#uses">How Can You Use XML?</a> </li></ul><h3><a name="intro"></a>What Is XML?</h3><blockquote>   <p>XML is a text-based markup language that is fast becoming the standard for     data interchange on the Web. As with HTML, you identify data using <a href="../glossary.html#tag">tag</a>s     (identifiers enclosed in angle brackets, like this: &lt;...&gt;). Collectively,     the tags are known as &quot;markup&quot;.</p>  <p>But unlike HTML, XML tags tell you what the data <i>means</i>, rather than     how to display it. Where an HTML tag says something like &quot;display this     data in bold font&quot; (<code>&lt;b&gt;...&lt;/b&gt;</code>), an XML tag     acts like a field name in your program. It puts a label on a piece of data     that identifies it (for example: <code>&lt;message&gt;...&lt;/message&gt;</code>).</p>  <p>In the same way that you define the field names for a data structure, you     are free to use any XML tags that make sense for a given application. Naturally,     though, for multiple applications to use the same XML data, they have to agree     on the tag names they intend to use.</p>  <p>Here is an example of some XML data you might use for a messaging application:</p>  <pre><b>&lt;message&gt;</b>    <b>&lt;to&gt;</b>you@yourAddress.com<b>&lt;/to&gt;</b>    <b>&lt;from&gt;</b>me@myAddress.com<b>&lt;/from&gt;</b>    <b>&lt;subject&gt;</b>XML Is Really Cool<b>&lt;/subject&gt;</b>    <b>&lt;text&gt;</b>       How many ways is XML cool? Let me count the ways...    <b>&lt;/text&gt;</b><b>&lt;/message&gt;</b></pre>  <blockquote>     <p><b>Note: </b>Throughout this tutorial, we use boldface text to highlight       things we want to bring to your attention. XML does not require anything       to be in bold!</p>  </blockquote></blockquote><blockquote>   <p>The tags in this example identify the message as a whole, the destination     and sender addresses, the subject, and the text of the message. As in HTML,     the <code>&lt;to&gt;</code> tag has a matching end tag: <code>&lt;/to&gt;</code>.     The data between the tag and and its matching end tag defines an <a href="../glossary.html#element">element</a>     of the XML data. Note, too, that the content of the <code>&lt;to&gt;</code>     tag is entirely contained within the scope of the <code>&lt;message&gt;..&lt;/message&gt;</code>     tag. It is this ability for one tag to contain others that gives XML its ability     to represent hierarchical data structures</p>  <p>Once again, as with HTML, whitespace is essentially irrelevant, so you can     format the data for readability and yet still process it easily with a program.     Unlike HTML, however, in XML you could easily search a data set for messages     containing &quot;cool&quot; in the subject, because the XML tags identify     the content of the data, rather than specifying its representation. </p></blockquote><h4><a name="tags"></a>Tags and Attributes</h4><blockquote>   <p>Tags can also contain <a href="../glossary.html#attribute">attributes</a>     -- additional information included as part of the tag itself, within the tag's     angle brackets. The following example shows an email message structure that     uses attributes for the &quot;to&quot;, &quot;from&quot;, and &quot;subject&quot;     fields:</p>  <pre>&lt;message <b>to=&quot;</b>you@yourAddress.com<b>&quot;</b><b> from=</b>&quot;me@myAddress.com<b>&quot;</b>          <b>subject=&quot;</b>XML Is Really Cool<b>&quot;</b>&gt;      <br>    &lt;text&gt;       How many ways is XML cool? Let me count the ways...    &lt;/text&gt;&lt;/message&gt;</pre>  <p></p>  <p>As in HTML, the attribute name is followed by an equal sign and the attribute     value, and multiple attributes are separated by spaces. Unlike HTML, however,     in XML commas between attributes are not ignored -- if present, they generate     an error. </p>  <p>Since you could design a data structure like <code>&lt;message&gt;</code>     equally well using either attributes or tags, it can take a considerable amount     of thought to figure out which design is best for your purposes. The last     part of this tutorial, <a href="4_design.html">Designing an XML Data Structure</a>,     includes ideas to help you decide when to use attributes and when to use tags.</p></blockquote><h4><a name="empty"></a>Empty Tags</h4><blockquote>   <p>One really big difference between XML and HTML is that an XML document is     always constrained to be <a href="4_design.html">well formed</a>. There are     several rules that determine when a document is well-formed, but one of the     most important is that every tag has a closing tag. So, in XML, the <code>&lt;/to&gt;</code>     tag is not optional. The <code>&lt;to&gt;</code> element is never terminated     by any tag other than <code>&lt;/to&gt;</code>. </p>  <blockquote>     <p><b><a name="nesting"></a>Note: </b>Another important aspect of a well-formed       document is that all tags are completely nested. So you can have <code>&lt;message&gt;..&lt;to&gt;..&lt;/to&gt;..&lt;/message&gt;</code>,       but never <code>&lt;message&gt;..&lt;to&gt;..&lt;/message&gt;..&lt;/to&gt;</code>.       A complete list of requirements is contained in the list of XML Frequently       Asked Questions (FAQ) at <a href="http://www.ucc.ie/xml/#FAQ-VALIDWF"><code>http://www.ucc.ie/xml/#FAQ-VALIDWF</code></a>.       (This FAQ is on the w3c &quot;Recommended Reading&quot; list at <a href="http://www.w3.org/XML/"><code>http://www.w3.org/XML/</code></a>.)</p>  </blockquote>  <p>Sometimes, though, it makes sense to have a tag that stands by itself. For     example, you might want to add a &quot;flag&quot; tag that marks message as     important. A tag like that doesn't enclose any content, so it's known as an     &quot;empty tag&quot;. You can create an empty tag by ending it with <code>/&gt;</code>     instead of <code>&gt;</code>. For example, the following message contains     such a tag:</p>  <pre>&lt;message to=&quot;you@yourAddress.com&quot; from=&quot;me@myAddress.com&quot;          subject=&quot;XML Is Really Cool&quot;&gt;    <b>&lt;flag/&gt;</b>      <br>    &lt;text&gt;       How many ways is XML cool? Let me count the ways...    &lt;/text&gt;&lt;/message&gt;</pre>  <b>Note: </b>The empty tag saves you from having to code <code>&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="2_specs.html#DTD">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.   <br>  <p></p>  <p></p></blockquote><h4><a name="comments"></a>Comments in XML Files</h4><blockquote>   <p>XML comments look just like HTML comments:</p>  <pre>&lt;message to=&quot;you@yourAddress.com&quot; from=&quot;me@myAddress.com&quot;          subject=&quot;XML Is Really Cool&quot;&gt;    <b>&lt;!-- This is a comment --&gt;</b>    &lt;text&gt;       How many ways is XML cool? Let me count the ways...    &lt;/text&gt;&lt;/message&gt;</pre>  <p></p></blockquote><p></p><h4><a name="prolog"></a>The XML Prolog</h4><blockquote>   <p>To complete this journeyman's introduction to XML, note that an XML file     always starts with a <a href="../glossary.html#prolog">prolog</a>. The minimal     prolog contains a <a href="../glossary.html#declaration">declaration</a> that     identifies the document as an XML document, like this:</p>  <pre>&lt;?xml version="1.0"?&gt;</pre>  <p>The declaration may also contain additional information, like this:</p>  <pre>&lt;?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?&gt;</pre>  <p>The XML declaration is essentially the same as the HTML header, <code>&lt;html&gt;</code>,     except that it uses <code>&lt;?..?&gt;</code> and it may contain the following     attributes:</p>  <dl>     <dl>       <dt><b>version</b></dt>      <dd>Identifies the version of the XML markup language used in the data.         This attribute is not optional.</dd>      <dt><b>encoding</b></dt>      <dd>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.)</dd>      <dt><b>standalone</b></dt>      <dd>Tells whether or not this document references an external <a href="../glossary.html#entity">entity</a>         or an external data type specification (see below). If there are no external         references, then &quot;yes&quot; is appropriate</dd>    </dl>  </dl>  <p>The prolog can also contain definitions of <a href="../glossary.html#entity">entities</a>     (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="2_specs.html#DTD">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 

⌨️ 快捷键说明

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