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

📄 introxml2.html

📁 j2eePDF格式的电子书
💻 HTML
📖 第 1 页 / 共 3 页
字号:
<?xml version="1.0" encoding="ISO-8859-1"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">  <head>    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />    <meta http-equiv="Content-Style-Type" content="text/css" />    <title>Introduction to XML</title>    <link rel="StyleSheet" href="document.css" type="text/css" media="all" />    <link rel="StyleSheet" href="catalog.css" type="text/css" media="all" />    <link rel="Table of Contents" href="J2EETutorialTOC.html" />    <link rel="Previous" href="IntroXML.html" />    <link rel="Next" href="IntroXML3.html" />    <link rel="Index" href="J2EETutorialIX.html" />  </head>  <body>    <table width="550" summary="layout" id="SummaryNotReq1">      <tr>	<td align="left" valign="center">	<font size="-1">	<a href="http://java.sun.com/j2ee/1.4/download.html#tutorial" target="_blank">Download</a>	<br>	<a href="http://java.sun.com/j2ee/1.4/docs/tutorial/information/faq.html" target="_blank">FAQ</a>	<br>	<a href="http://java.sun.com/j2ee/1.4/docs/tutorial/information/history.html" target="_blank">History</a>	</td>        <td align="center" valign="center"><a accesskey="p" href="IntroXML.html"><img id="LongDescNotReq1" src="images/PrevArrow.gif" width="26" height="26" border="0" alt="Prev" /></a><a accesskey="c" href="J2EETutorialFront.html"><img id="LongDescNotReq1" src="images/UpArrow.gif" width="26" height="26" border="0" alt="Home" /></a><a accesskey="n" href="IntroXML3.html"><img id="LongDescNotReq3" src="images/NextArrow.gif" width="26" height="26" border="0" alt="Next" /></a><a accesskey="i" href="J2EETutorialIX.html"></a>        </td>	<td align="right" valign="center">	<font size="-1">	<a href="http://java.sun.com/j2ee/1.4/docs/api/index.html" target="_blank">API</a>	<br>	<a href="http://java.sun.com/j2ee/1.4/docs/tutorial/information/search.html" target="_blank">Search</a>	<br>	<a href="http://java.sun.com/j2ee/1.4/docs/tutorial/information/sendusmail.html" target="_blank">Feedback</a></font>	</font>	</td>      </tr>    </table>    <img src="images/blueline.gif" width="550" height="8" ALIGN="BOTTOM" NATURALSIZEFLAG="3" ALT="Divider">    <blockquote><a name="wp64813"> </a><h2 class="pHeading1">Introduction to XML</h2><a name="wp64798"> </a><p class="pBody">This section 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.</p><a name="wp63885"> </a><h3 class="pHeading2">What Is XML?</h3><a name="wp63886"> </a><p class="pBody">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 tags (identifiers enclosed in angle brackets, like this: <code class="cCode">&lt;...&gt;</code>). Collectively, the tags are known as &quot;markup&quot;.</p><a name="wp63887"> </a><p class="pBody">But unlike HTML, XML tags <span style="font-style: italic">identify</span> the data, rather than specifying how to display it. Where an HTML tag says something like &quot;display this data in bold font&quot; (<code class="cCode">&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 class="cCode">&lt;message&gt;...&lt;/message&gt;</code>). </p><hr><a name="wp63888"> </a><p class="pNote">Note: Since identifying the data gives you some sense of what <span style="font-style: italic">means</span> (how to interpret it, what you should do with it), XML is sometimes described as a mechanism for specifying the <span style="font-style: italic">semantics</span> (meaning) of the data.</p><hr><a name="wp63889"> </a><p class="pBody">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><a name="wp63890"> </a><p class="pBody">Here is an example of some XML data you might use for a messaging application:</p><div class="pPreformattedRelative"><pre class="pPreformattedRelative">&lt;message&gt;<span style="font-weight: bold">&nbsp;&nbsp;&lt;to&gt;</span>you@yourAddress.com<span style="font-weight: bold">&lt;/to&gt;&nbsp;&nbsp;&lt;from&gt;</span>me@myAddress.com<span style="font-weight: bold">&lt;/from&gt;&nbsp;&nbsp;&lt;subject&gt;</span>XML Is Really Cool<span style="font-weight: bold">&lt;/subject&gt;&nbsp;&nbsp;&lt;text&gt;</span>&nbsp;&nbsp;&nbsp;&nbsp;How many ways is XML cool? Let me count the ways...<span style="font-weight: bold">&nbsp;&nbsp;&lt;/text&gt;</span>&lt;/message&gt;<a name="wp63891"> </a></pre></div><hr><a name="wp63892"> </a><p class="pNote">Note: 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><hr><a name="wp63893"> </a><p class="pBody">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 class="cCode">&lt;to&gt;</code> tag has a matching end tag: <code class="cCode">&lt;/to&gt;</code>. The data between the tag and its matching end tag defines an element of the XML data. Note, too, that the content of the <code class="cCode">&lt;to&gt;</code> tag is entirely contained within the scope of the <code class="cCode">&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><a name="wp63894"> </a><p class="pBody">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><a name="wp63896"> </a><h4 class="pHeading3">Tags and Attributes</h4><a name="wp63897"> </a><p class="pBody">Tags can also contain attributes--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 <code class="cCode">&quot;to&quot;</code>, <code class="cCode">&quot;from&quot;</code>, and <code class="cCode">&quot;subject&quot;</code> fields:</p><div class="pPreformattedRelative"><pre class="pPreformattedRelative">&lt;message <span style="font-weight: bold">to=&quot;</span>you@yourAddress.com<span style="font-weight: bold">&quot; from=</span>&quot;me@myAddress.com<span style="font-weight: bold">&quot;</span> <span style="font-weight: bold">&nbsp;&nbsp;&nbsp;&nbsp;subject=&quot;</span>XML Is Really Cool<span style="font-weight: bold">&quot;</span>&gt; &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="wp63898"> </a></pre></div><a name="wp63899"> </a><p class="pBody">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><a name="wp63900"> </a><p class="pBody">Since you could design a data structure like <code class="cCode">&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. <a  href="IntroXML5.html#wp64992">Designing an XML Data Structure</a>, includes ideas to help you decide when to use attributes and when to use tags.</p><a name="wp63905"> </a><h4 class="pHeading3">Empty Tags</h4><a name="wp63906"> </a><p class="pBody">One really big difference between XML and HTML is that an XML document is always constrained to be well formed. 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 class="cCode">&lt;/to&gt;</code> tag is not optional. The <code class="cCode">&lt;to&gt;</code> element is never terminated by any tag other than <code class="cCode">&lt;/to&gt;</code>. </p><hr><a name="wp63908"> </a><p class="pNote">Note: Another important aspect of a well-formed document is that all tags are completely nested. So you can have <code class="cCode">&lt;message&gt;..&lt;to&gt;..&lt;/to&gt;..&lt;/message&gt;</code>, but never <code class="cCode">&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 <code class="cCode"><a  href="http://www.ucc.ie/xml/#FAQ-VALIDWF" target="_blank">http://www.ucc.ie/xml/#FAQ-VALIDWF</a></code>. (This FAQ is on the w3c &quot;Recommended Reading&quot; list at <code class="cCode"><a  href="http://www.w3.org/XML/" target="_blank">http://www.w3.org/XML/</a></code>.)</p><hr><a name="wp63909"> </a><p class="pBody">Sometimes, though, it makes sense to have a tag that stands by itself. For example, you might want to add a <code class="cCode">&quot;flag&quot;</code> 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 class="cCode">/&gt;</code> instead of <code class="cCode">&gt;</code>. For example, the following message contains such a tag:</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;flag/&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="wp63910"> </a>

⌨️ 快捷键说明

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