📄 7b_pe.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN" ><!--NEWPAGE-- ><HTML ><HEAD ><TITLE >PE parsing</TITLE ><STYLE TYPE=text/css ><!-- -- ></STYLE ></HEAD ><BODY BGCOLOR=#ffffff ><HR ><B >HtmlDiff: </B >Here is the <A href=#DIFF0 >first difference.</A > There are 2 differences. <IMG src=../diffpics/oold.gif ><STRIKE>is old.</STRIKE><IMG src=../diffpics/onew.gif ><STRONG><I> is new. </I></STRONG><HR ><TABLE WIDTH=100% ><TR > <TD ALIGN=left > <A HREF=7a_pe.html ><IMG SRC=../images/PreviousArrow.gif WIDTH=26 HEIGHT=26 ALIGN=top BORDER=0 ALT="Previous | " ></A ><A HREF=8_lex.html ><IMG SRC=../images/NextArrow.gif WIDTH=26 HEIGHT=26 ALIGN=top BORDER=0 ALT="Next | " ></A ><A HREF=../alphaIndex.html ><IMG SRC=../images/xml_IDX.gif WIDTH=26 HEIGHT=26 ALIGN=top BORDER=0 ALT="Index | " ></A ><A HREF=../TOC.html ><IMG SRC=../images/xml_TOC.gif WIDTH=26 HEIGHT=26 ALIGN=top BORDER=0 ALT="TOC | " ></A ><A HREF=../index.html ><IMG SRC=../images/xml_Top.gif WIDTH=26 HEIGHT=26 ALIGN=top 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 >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 ><H2 >Parsing the Parameterized DTD</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=../overview/2_specs.html#schema >Schema Proposals</A ></LI > <LI ><A HREF=../dom/index.html >Manipulating Document Contents with the Document Object Model</A ></LI > </UL > <P ><B ><I ></I ></B ><B ><I >Exercise Links</I ></B ></P > <UL > <LI ><A HREF=work/Echo10-08.log >Echo10-08.log</A ></LI > <LI ><A HREF=samples/slideshow3.dtd >slideshow3.dtd</A ></LI > <LI ><A HREF=samples/slideSample09.xml >slideSample09.xml</A ></LI > <LI ><A name=DIFF0 ></A ><A href=#DIFF1 ><IMG src=../diffpics/oold.gif ></A ><STRIKE >copyright.xml </STRIKE ><A name=DIFF0 ></A ><A href=#DIFF1 ><IMG src=../diffpics/onew.gif ></A ><STRONG ><I ><A HREF=samples/copyright.xml >copyright.xml </A ></STRONG ></I ></LI > <LI ><A HREF=work/Echo10-09.log >Echo10-09.log</A ></LI > </UL > <DL > <DT ><B ><I >External Links</I ></B ></DT > </DL > <UL > <LI ><A HREF=http://www.w3.org/TR/xhtml-modularization/ >Modularized XHTML</A ></LI > </UL > <P ><B ><I >Glossary Terms</I ></B ></P > <DL > <DD ><A HREF=../glossary.html#namespace >namespace</A ></DD > </DL > </TD > </TR ></TABLE ><P >This section uses the Echo program to see what happens when you reference <CODE >xhtml.dtd</CODE > in <CODE >slideshow.dtd</CODE >. It also covers the kinds of warnings that are generated by the SAX parser when a DTD is present. <BLOCKQUOTE > <P >Note: The output described in this section is contained in <A HREF=work/Echo10-08.log ><CODE >Echo10-08.log</CODE ></A >.</P ></BLOCKQUOTE ><P >When you try to echo the slide presentation, you find that it now contains a new error. The relevant part of the output is shown here (formatted for readability): <BLOCKQUOTE > <PRE ><?xml version='1.0' encoding='UTF-8'?** Parsing error, line 22, uri file:.../slideshow.dtd<B >Element "title" was already declared.</B >org.xml.sax.SAXParseException: ...</PRE ></BLOCKQUOTE ><P >It seems that <CODE >xhtml.dtd</CODE > defines a <CODE >title</CODE > element which is entirely different from the <CODE >title</CODE > element defined in the slideshow DTD. Because there is no hierarchy in the DTD, these two definitions conflict. </P ><BLOCKQUOTE > <P ><B >Note:</B ><BR > The <A HREF=http://www.w3.org/TR/xhtml-modularization/ >Modularized XHTML</A > DTD also defines a <CODE >title</CODE > element that is intended to be the document title, so we can't avoid the conflict by changing <CODE >xhtml.dtd</CODE > -- the problem would only come back to haunt us later.</P ></BLOCKQUOTE ><P >You could also use XML <A HREF=../glossary.html#namespace >namespace</A >s to resolve the conflict, or use one of the more hierarchical schema proposals described in <A HREF=../overview/2_specs.html#schema >Schema Proposals</A >. For now, though, let's simply rename the <CODE >title</CODE > element in <CODE >slideshow.dtd</CODE >.</P ><BLOCKQUOTE > <P ><B >Note:</B ><BR > The XML shown here is contained in <A HREF=samples/slideshow3.dtd ><CODE >slideshow3.dtd</CODE ></A > and <A HREF=samples/slideSample09.xml ><CODE >slideSample09.xml</CODE ></A >, which references <A HREF=samples/copyright.xml ><CODE >copyright.xml</CODE ></A >. The results of processing are shown in <A HREF=work/Echo10-09.log ><CODE >Echo10-09.log</CODE ></A >.</P ></BLOCKQUOTE ><P >To keep the two title elements separate, we'll resort to a "hyphenation hierarchy". Make the changes highlighted below to change the name of the <CODE >title</CODE > element in <CODE >slideshow.dtd</CODE > to <CODE >slide-title</CODE >:</P ><BLOCKQUOTE > <PRE ><!ELEMENT slide (image?, <B >slide-</B >title?, item*)<!ATTLIST slide type (tech | exec | all) #IMPLIED<!-- Defines the %inline; declaration --<!ENTITY % xhtml SYSTEM "xhtml.dtd"%xhtml;<!ELEMENT <B >slide-</B >title (%inline;)*</PRE ></BLOCKQUOTE ><P > The next step is to modify the XML file to use the new element name. To do that, make the changes highlighted below:</P ><BLOCKQUOTE > <PRE >...<slide type="all"<<B >slide-</B >titleWake up to ... </<B >slide-</B >title</slide...<!-- OVERVIEW --<slide type="all"<<B >slide-</B >titleOverview</<B >slide-</B >title<item...</PRE ></BLOCKQUOTE ><P >Now run the Echo program on this version of the slide presentation. It should run to completion and display output like that shown in <A HREF=work/Echo10-09.log ><CODE >Echo10-09.log</CODE ></A >.</P ><P >Congratulations! You have now read a fully validated XML document. The changes you made had the effect of putting your DTD's <CODE >title</CODE > element into a slideshow "namespace" that you artificially constructed by hyphenating the name. Now the <CODE >title</CODE > element in the "slideshow namespace" (<CODE >slide-title</CODE >, really) no longer conflicts with the <CODE >title</CODE > element in <CODE >xhtml.dtd</CODE >. In the next section of the tutorial, you'll see how to do that without renaming the definition. To finish off this section, we'll take a look at the kinds of warnings that the validating parser can produce when processing the DTD. </P ><H3 ><A NAME=DTDwarn ></A >DTD Warnings</H3 ><P >As mentioned earlier in this tutorial, warnings are generated only when the SAX parser is processing a DTD. Some warnings are generated only by the validating parser. The nonvalidating parser's main goal is operate as rapidly as possible, but it too generates some warnings. (The explanations that follow tell which does what.)</P >The XML specification suggests that warnings should be generated as result of:<BR ><UL > <LI > <P > Providing additional declarations for entities, attributes, or notations.<BR > (Such declarations are ignored. Only the first is used. Also, note that duplicate definitions of <I >elements</I > always produce a fatal error when validating, as you saw earlier.) </P > </LI > <LI > <P >Referencing an undeclared element type.<BR > (A validity error occurs only if the undeclared type is actually used in the XML document. A warning results when the undeclared element is referenced in the DTD.) </P > </LI > <LI > <P > Declaring attributes for undeclared element types.</P > </LI ></UL ><P >The Java XML SAX parser also emits warnings in other cases, such as: </P ><UL > <LI > <P >No <!DOCTYPE ... when validating.<BR > <A name=DIFF1 ></A ><A href=#DIFF0 ><IMG src=../diffpics/oold.gif ></A ><STRIKE >[To be verified. Currently generates an error.] </STRIKE ><FONT COLOR=#FF0000 ></FONT ></P > </LI > <LI > <P > Referencing an undefined parameter entity when not validating.<BR > (When validating, an error results. Although nonvalidating parsers are not required to read parameter entities, the Java XML parser does so. Since it is not a requirement, the Java XML parser generates a warning, rather than an error.)</P > </LI > <LI > Certain cases where the character-encoding declaration does not look right.</LI ></UL ><P >At this point, you have digested many XML concepts, including DTDs, external entities. You have also learned your way around the SAX parser. The remainder of the SAX tutorial covers advanced topics that you will only need to understand if you are writing SAX-based applications. If your primary goal is to write DOM-based apps, you can skip ahead to <A HREF=../dom/index.html >Manipulating Document Contents with the Document Object Model</A >.</P ><BLOCKQUOTE > <HR SIZE=4 ></BLOCKQUOTE ><P ><P > <TABLE WIDTH=100% ><TR > <TD ALIGN=left > <A HREF=7a_pe.html ><IMG SRC=../images/PreviousArrow.gif WIDTH=26 HEIGHT=26 ALIGN=top BORDER=0 ALT="Previous | " ></A ><A HREF=8_lex.html ><IMG SRC=../images/NextArrow.gif WIDTH=26 HEIGHT=26 ALIGN=top BORDER=0 ALT="Next | " ></A ><A HREF=../alphaIndex.html ><IMG SRC=../images/xml_IDX.gif WIDTH=26 HEIGHT=26 ALIGN=top BORDER=0 ALT="Index | " ></A ><A HREF=../TOC.html ><IMG SRC=../images/xml_TOC.gif WIDTH=26 HEIGHT=26 ALIGN=top BORDER=0 ALT="TOC | " ></A ><A HREF=../index.html ><IMG SRC=../images/xml_Top.gif WIDTH=26 HEIGHT=26 ALIGN=top 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 >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 ></BODY ></HTML >
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -