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

📄 index.html

📁 《Big C++ 》Third Edition电子书和代码全集-Part1
💻 HTML
📖 第 1 页 / 共 3 页
字号:
				<td align='center'>Ampersand</td>
			</tr>
			<tr>
				<td align='center'>&apos;</td>
				<td align='center'>&amp;apos;</td>
				<td align='center'>Apostrophe</td>
			</tr>
			<tr>
				<td align='center'>&quot;</td>
				<td align='center'>&amp;quot;</td>
				<td align='center'>Quotation mark</td>
			</tr>
		</table>
	</li>
</ul>

</font>

<hr><h2><font color="#009999">29.4 Document Type Definitions (cont.)</font></h2>
<font size="+1">

<ul>
	<li>Expressions to describe children:
		<br><br>
		<table border='1'>
			<tr bgcolor='#00ffff'>
				<th>Rule Description</th>
				<th>Element Content</th>
			</tr>
			<tr>
				<td align='center'><tt>EMPTY</tt></td>
				<td align='center'>No children allowed</td>
			</tr>
			<tr>
				<td align='center'>(E*)</td>
				<td align='center'>Any sequence of 0 or more elements E</td>
			</tr>
			<tr>
				<td align='center'>(E+)</td>
				<td align='center'>Any sequence of 1 or more elements E</td>
			</tr>
			<tr>
				<td align='center'>(E?)</td>
				<td align='center'>Optional element E (0 or 1)</td>
			</tr>
			<tr>
				<td align='center'>(E1, E2, . . .)</td>
				<td align='center'>Element E1, followed by E2, ...</td>
			</tr>
			<tr>
				<td align='center'>(E1|E2|. . .)</td>
				<td align='center'>Element E1 or E2 or ...</td>
			</tr>
			<tr>
				<td align='center'>(<tt>#PCDATA</tt>)</td>
				<td align='center'>Text only (parsable)</td>
			</tr>
			<tr>
				<td align='center'>(<tt>#PCDATA</tt>|E1|E2|. . .)*</td>
				<td align='center'>Any sequence of text and elements E1, E2, ..., in
					any order</td>
			</tr>
			<tr>
				<td align='center'><tt>ANY</tt></td>
				<td align='center'>Any children allowed</td>
			</tr>
		</table>
	</li>
</ul>

</font>

<hr><h2><font color="#009999">29.4 Document Type Definitions (cont.)</font></h2>
<font size="+1">

<ul>
	<li>Flowchart describing the regular expressions:
		<script><!--
			image( "fig09.png" )
		//--></script>
	</li>
</ul>

</font>

<hr><h2><font color="#009999">29.4 Document Type Definitions (cont.)</font></h2>
<font size="+1">

<ul>
	<li>Expressions can be combined:
		<blockquote><tt>
			&lt;!ELEMENT section (title, (paragraph | (image, title?))+)&gt;
		</tt></blockquote>
	</li>
	<li>Defines an element <tt>section</tt> whose children are:
		<ol>
			<li>A <tt>title</tt> element</li>
			<li>A sequence of one or more of:
				<ul>
					<li><tt>paragraph</tt> elements</li>
					<li><tt>image</tt> elements followed by optional <tt>title</tt>
						elements</li>
				</ul>
			</li>
		</ol>
	</li>
	<li>Avoid mixed content for DTDs</li>
	<li>Avoid <tt>ANY</tt> type in DTDs</li>
</ul>

</font>

<hr><h2><font color="#009999">29.4 Document Type Definitions (cont.)</font></h2>
<font size="+1">

<ul>
	<li>To describe an attribute:
		<blockquote><tt>
			&lt;!ATTLIST <i>Element Attribute Type Default</i>&gt;
		</tt></blockquote>
	</li>
	<li>Common attribute type descriptions:</li>
	<br>
	<table border=1>
		<tr bgcolor="#00ffff">
			<th>Type Description</th>
			<th>Attribute Type</th>
		</tr>
		<tr>
			<td align='center'><tt>CDATA</tt></td>
			<td align='center'>Any character data</td>
		</tr>
		<tr>
			<td align='center'>(N<sub>1</sub>|N<sub>2</sub>|. . .)</td>
			<td align='center'>One of N<sub>1</sub>, N<sub>2</sub>, ...</td>
		</tr>
	</table>
	<br>
	<li><tt>CDATA</tt> much like <tt>#PCDATA</tt> (encode same
		characters)</li>
</ul>

</font>

<hr><h2><font color="#009999">29.4 Document Type Definitions (cont.)</font></h2>
<font size="+1">

<ul>
	<li>To specify finite choices:
		<blockquote><tt>
			&lt;!ATTLIST price currency (USD | EUR | JPY) #REQUIRED&gt;
		</tt></blockquote>
	</li>
	<li>Choices may contain letters, numbers, <tt>-</tt>, <tt>_</tt> or
		<tt>.</tt></li>
	<li><tt>currency</tt> attribute <b>must</b> be specified</li>
	<li>Attribute Defaults:</li>
	<br>
	<table border='1'>
		<tr bgcolor='#00ffff'>
			<th>Default Declaration</th>
			<th>Explanation</th>
		</tr>
		<tr>
			<td align='center'><tt>#REQUIRED</tt></td>
			<td align='center'>Attribute is required</td>
		</tr>
		<tr>
			<td align='center'><tt>#IMPLIED</tt></td>
			<td align='center'>Attribute is optional</td>
		</tr>
		<tr>
			<td align='center'><i>N</i></td>
			<td align='center'>Default attribute, used if attribute not
				specified</td>
		</tr>
		<tr>
			<td align='center'><tt>#FIXED</tt> <i>N</i></td>
			<td align='center'>Attribute must either be unspecified or contain
				this value</td>
		</tr>
	</table>
</ul>

</font>

<hr><h2><font color="#009999">29.4 Document Type Definitions (cont.)</font></h2>
<font size="+1">

<ul>
	<li><tt>currency</tt> attribute is optional:
		<blockquote><tt>
			&lt;!ATTLIST price currency CDATA #IMPLIED&gt;
		</tt></blockquote>
		Some default currency implicitly assumed
	</li>
	<li>Better to explicitly supply default:
		<blockquote><tt>
			&lt;!ATTLIST price currency CDATA "USD"&gt;
		</tt></blockquote>
	</li>
	<li><tt>#FIXED</tt> not often used</li>
</ul>

</font>

<hr><h2><font color="#009999">Advanced Topic 29.1</font></h2>
<font size="+1">
<hr color="#00ffff" size="6">

<p><font color="#009999">The XML Schema Specification</font></p>

<ul>
	<li>DTDs don't specify type of data</li>
	<li>E.g., can't constrain an element to an int, or float, or date</li>
	<li>XML Schema Definition currently being developed (2004)</li>
	<li>Addresses this problem</li>
	<li>E.g.:
		<blockquote><tt>
			&lt;xsd:element name="quantity" type="xsd:integer"/&gt;
		</tt></blockquote>
	</li>
</ul>

</font>

<hr><h2><font color="#009999">Advanced Topic 29.1</font></h2>
<font size="+1">
<hr color="#00ffff" size="6">

<ul>
	<li>Some built-in types</li>
	<table border='1'>
		<tr bgcolor='#00ffff'>
			<th>XML Schema Type</th>
			<th>Meaning</th>
		</tr>
		<tr>
			<td align='center'><tt>string</tt></td>
			<td align='center'>Any string</td>
		</tr>
		<tr>
			<td align='center'><tt>integer</tt></td>
			<td align='center'>An integer</td>
		</tr>
		<tr>
			<td align='center'><tt>double</tt></td>
			<td align='center'>A floating-point number</td>
		</tr>
		<tr>
			<td align='center'><tt>boolean</tt></td>
			<td align='center'>False or True</td>
		</tr>
		<tr>
			<td align='center'><tt>date</tt></td>
			<td align='center'>E.g., 2001-01-04</td>
		</tr>
		<tr>
			<td align='center'><tt>time</tt></td>
			<td align='center'>E.g., 05:43</td>
		</tr>
	</table>
</ul>

</font>

<hr><h2><font color="#009999">Advanced Topic 29.1 (cont.)</font></h2>
<font size="+1">
<hr color="#00ffff" size="6">

<ul>
	<li>Allows you to define complex types:
		<blockquote>
<pre>&lt;xsd:complexType name="Address"&gt;
   &lt;xsd:sequence&gt;
      &lt;xsd:element name="name" type="xsd:string"/&gt;
      &lt;xsd:element name="company" type="xsd:string"/&gt;
      &lt;xsd:element name="street" type="xsd:string"/&gt;
      &lt;xsd:element name="city" type="xsd:string"/&gt;
      &lt;xsd:element name="state" type="xsd:string"/&gt;
      &lt;xsd:element name="zip" type="xsd:string"/&gt;
   &lt;/xsd:sequence&gt;
&lt;/xsd:complexType&gt;</pre>
		</blockquote>
	</li>
</ul>

</font>

<hr><h2><font color="#009999">Advanced Topic 29.1 (cont.)</font></h2>
<font size="+1">
<hr color="#00ffff" size="6">

<ul>
	<li>To be used:
		<blockquote><tt>
			&lt;xsd:element name="shipto" type="Address"/&gt;<br>
			&lt;xsd:element name="billto" type="Address"/&gt;
		</tt></blockquote>
	</li>
</ul>

</font>

<hr><h2><font color="#009999">29.5 Parsing with DTDs</font></h2>
<font size="+1">

<ul>
	<li>Good idea for all XML documents to reference a DTD
		<ul>
			<li>Parser can check for errors</li>
			<li>Be more intelligent about parsing</li>
		</ul>
	</li>
	<li>2 ways to reference a DTD:
		<ol>
			<li>Inline DTD in document</li>
			<li>Refer to external DTD</li>
		</ol>
	</li>
	<li>DTD introduced w/the <tt>DOCTYPE</tt> declaration</li>
</ul>

</font>

<hr><h2><font color="#009999">29.5 Parsing with DTDs (cont.)</font></h2>
<font size="+1">

<ul>
	<li>If DTD is inline:
		<blockquote><tt>
			&lt;!DOCTYPE <i>rootElement</i> [<i>rules</i>]&gt;
		</tt></blockquote>
	</li>
	<li>E.g., an item list:
		<script><!-- 
			iframeWrapCode( "itemInlineDtd.xml", "80%", "40%" )
		//--></script>
	</li>
</ul>

</font>

<hr><h2><font color="#009999">29.5 Parsing with DTDs (cont.)</font></h2>
<font size="+1">

<ul>
	<li>Store complex DTDs externally</li>
	<li>Use <tt>SYSTEM</tt> keyword to indicate external location</li>
	<li>For a local file:
		<blockquote><tt>
			&lt;!DOCTYPE items SYSTEM "items.dtd"&gt;
		</tt></blockquote>
	</li>
	<li>For a page on the Web:
		<blockquote><tt>
			&lt;!DOCTYPE items<br>
			&nbsp;&nbsp;&nbsp;SYSTEM "http://www.mycompany.com/dtds/items.dtd"&gt;
		</tt></blockquote>
	</li>
</ul>

</font>

<hr><h2><font color="#009999">29.5 Parsing with DTDs (cont.)</font></h2>
<font size="+1">

<ul>
	<li>Common DTDs can use the <tt>PUBLIC</tt> keyword to indicate an
		identifier:
		<blockquote>
<pre>&lt;!DOCTYPE web-app
   PUBLIC
   "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
   "http://java.sun.com/j2ee/dtds/web-app_2_3.dtd"&gt;</pre>
		</blockquote>
	</li>
	<li>The parser won't retrieve a DTD it already knows from its identifier</li>
</ul>

</font>

<hr><h2><font color="#009999">29.5 Parsing with DTDs (cont.)</font></h2>
<font size="+1">

<ul>
	<li>Validate documents that have a DTD
		<ul>
			<li>Parser checks children and elements</li>
			<li>Reports errors</li>
		</ul>
	<li>To turn validation on in Xerces:
		<blockquote><tt>
			parser-&gt;setFeature(XMLUni::fgDOMValidation, true);
		</tt></blockquote>
	</li>
</ul>

</font>

<hr><h2><font color="#009999">29.5 Parsing with DTDs (cont.)</font></h2>
<font size="+1">

<ul>
	<li>Register an error handler to have errors reported</li>
	<li>Handler is a class inherited from <tt>DOMErrorHandler</tt></li>
	<li>Override method:
		<blockquote><tt>
			bool handleError(const DOMError&amp; domError)
		</tt></blockquote>
		<ul>
			<li>Should log error</li>
			<li>Return <tt>true</tt> if non-fatal</li>
			<li>Sample program defines <tt>SimpleErrorHandler</tt>
		</ul>
	</li>
	<li>To install the handler:
		<blockquote><tt>
			DOMErrorHandler* handler = new SimpleErrorHandler();<br>
			parser-&gt;setErrorHandler(handler);
		</tt></blockquote>
	</li>
</ul>

</font>

<hr><h2><font color="#009999">29.5 Parsing with DTDs (cont.)</font></h2>
<font size="+1">

<ul>
	<li>With a DTD, parser can strip out whitespace for you</li>
	<li>To get this behavior:
		<blockquote>
<pre>parser-&gt;setFeature(XMLUni::fgDOMWhitespaceInElementContent,
   false);</pre>
		</blockquote>
	</li>
	<li>Parser can fill in default attributes:
		<blockquote>
<pre>XMLCh* attribute_value
   = price_element-&gt;getAttribute("currency");
   <font color="#0000cc">// Gets "USD" if no currency specified</font></pre>
</ul>

</font>

<hr><h2><font color="#009999">29.5 Parsing with DTDs (cont.)</font></h2>
<font size="+1">

<ul>
	<li>The following program is simpler than the one from sect. 29.2</li>
	<li>Parses
		<a target='bigc' href='Code/dtd/items.xml'><tt>items.xml</tt></a>
		using
		<a target='bigc' href='Code/dtd/items.dtd'><tt>items.dtd</tt></a><br>
		<font size='+0'>(Note: might not actually display in a browser.  Check
			source)</font>
	</li>
	<li>Uses the same files:
		<a target='bigc' href='Code/dtd/item.h'><tt>item.h</tt></a>,
		<a target='bigc' href='Code/dtd/item.cpp'><tt>item.cpp</tt></a>,
		<a target='bigc' href='Code/dtd/product.h'><tt>product.h</tt></a>, and
		<a target='bigc' href='Code/dtd/product.cpp'><tt>product.cpp</tt></a>
	</li>
</ul>

</font>

<hr><h2><font color="#009999">29.5 Parsing with DTDs (parser2.cpp)</font></h2>
<font size="+1">

<script><!-- 
	iframeWrapCode( "dtd/parser2.cpp", "90%", "80%" )
//--></script>

</font>

<hr><h2><font color="#009999">Chapter Summary</font></h2>
<font size="+1">
<hr color="#00ffff" size="6">

<ol>
	<li>XML allows you to encode complex data, independent from any programming
		language, in a form that a recipient can parse easily, and that is
		resilient to change</li>
	<li>An XML data set is called a document. It starts out with a header and
		contains elements and text. An element can contain text, subelements, or
		both (mixed content). For data descriptions, avoid mixed content.
		Elements can have attributes. Use attributes to describe how to interpret
		the element content</li>
	<li>A parser is a program that reads a document, checks whether it is
		syntactically correct, and takes some action as it processes the document.
		There are two kinds of XML parsers. SAX fires events as it analyzes a
		document. DOM builds a document tree</li>
</ol>
</font>

<hr><h2><font color="#009999">Chapter Summary</font></h2>
<font size="+1">
<hr color="#00ffff" size="6">

<ol start='4'>
	<li>A DOMDocument object consists of nodes that are represented by objects of
		the DOMNode class or one of its derived classes. The most important derived
		classes are DOMElement and DOMText</li>
	<li>A DTD is a sequence of rules that describe the legal child elements and
		attributes for each element type. An XML document can contain its DTD or
		refer to a DTD that is stored elsewhere. When referencing an external DTD,
		you must supply a file name or URL</li>
	<li>It is best to use DTDs with XML files. When using DTDs, you should tell
		the parser to validate the document and to ignore white space. This greatly
		simplifies the implementation of the parser functions</li>
</ol>

</font>

</body>
</html>

⌨️ 快捷键说明

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