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

📄 3_apis.html

📁 XML_JAVA指南 书籍语言: 简体中文 书籍类型: 程序设计 授权方式: 免费软件 书籍大小: 377 KB
💻 HTML
📖 第 1 页 / 共 3 页
字号:
      in <A HREF=../sax/9_notatn.html>Using the DTDHandler and EntityResolver</A>.       This interface is extended by the <A name=DIFF19></A><A href=#DIFF20><IMG src=../diffpics/oold.gif></A><STRIKE>Java XML </STRIKE><TT><A name=DIFF20></A><A href=#DIFF21><IMG src=../diffpics/onew.gif></A><STRONG><I>com.sun.java.xml</STRONG></I></TT> interface <A HREF=../../api/com/sun/xml/parser/DtdEventListener.html><CODE>DtdEventListener</CODE></A>,       which adds methods like <CODE>startDtd</CODE> and <CODE>endDtd</CODE>.</DD>    <DT>&nbsp;</DT>    <DT><CODE><B><A NAME=EntityResolver></A>EntityResolver</B></CODE></DT>    <DD>The <CODE>resolveEntity</CODE> method is invoked when the parser must       identify data identified by a <A HREF=../glossary.html#URI>URI</A>. In       most cases, a URI is simply a <A HREF=../glossary.html#URL>URL</A>, which       specifies the location of a document, but in some cases the document may       be identified by a <A HREF=../glossary.html#URN>URN</A> -- a <I>public       identifier</I>, or name, that is unique in the web space. <A HREF=../glossary.html#URN></A>       The public identifier may be specified in addition to the URL. The <CODE>EntityResolver</CODE>       can then use the public identifier instead of the URL to find the document,       for example to access a local copy of the document if one exists.</DD>  </DL>  <P>A typical application provides a <CODE>DocumentHandler</CODE>, at a minimum.     Since the default implementations of the interfaces ignore all inputs except     for fatal errors, a robust implementation may want to provide an ErrorHandler     to report more errors or report them differently. </P>  <BLOCKQUOTE>     <P><B><A NAME=HandlerBase></A>Note:</B> The class <A HREF=../../api/org/xml/sax/HandlerBase.html><CODE>org.xml.sax.HandlerBase</CODE></A>       implements all of these interfaces with null methods, so you can override       the methods for events you need to process and ignore the methods for other       events.</P>  </BLOCKQUOTE>  <H4><A NAME=SaxPackages></A>Packages</H4>  <P>The SAX parser is defined in the following packages.</P>  <TABLE WIDTH=92% BORDER=1>    <TR>       <TD WIDTH=22% HEIGHT=25><B><I>Package</I></B></TD>      <TD WIDTH=78% HEIGHT=25><B><I>Description</I></B></TD>    </TR>    <TR>       <TD WIDTH=22%><A HREF=../../api/org/xml/sax/package-summary.html>org.xml.sax</A>       </TD>      <TD WIDTH=78%>Defines the SAX interfaces. The name &quot;<CODE>org.xml</CODE>&quot;         is the package prefix that was settled on by the group that defined the         SAX API. This package also defines <CODE>HandlerBase</CODE> -- a default         implementation of a base class for the various &quot;handlers&quot; defined         by the interfaces, as well as an <CODE>InputSource</CODE> class, which         encapsulates information that tells where the XML data is coming from.</TD>    </TR>    <TR>       <TD WIDTH=22%><A HREF=../../api/org/xml/sax/helpers/package-summary.html>org.xml.sax.helpers</A></TD>      <TD WIDTH=78%>         <P>This package is part of SAX. It defines the <CODE>ParserFactory</CODE>           class, which lets you acquire an instance of a parser either by specifying           a name string or by using the value defined by the <CODE>org.xml.sax.parser</CODE>           system property. This package also provides implementations for two           other interfaces defined in <CODE>org.xml.sax</CODE>, but these classes           are not needed when using Sun's Java XML SAX parsers.</P>      </TD>    </TR>    <TR>       <TD WIDTH=22%><A name=DIFF21></A><A href=#DIFF22><IMG src=../diffpics/onew.gif></A><STRONG><I><A HREF=../../api/javax/xml/parsers/package-frame.html>javax.xml.parsers</A></TD>          <TD WIDTH=78%>Defines the <CODE>SAXParserFactory</CODE> class which returns       the SAXParser. Also defines the <CODE>ParserConfigurationException</CODE>       class for reporting errors.</STRONG></I></TD>    </TR>    <TR>       <TD WIDTH=22%><A HREF=../../api/com/sun/xml/parser/package-summary.html>com.sun.xml.parser</A></TD>      <TD WIDTH=78%>Contains the Java XML parser (<CODE>com.sun.xml.parser.Parser</CODE>),         validating parser (<CODE>com.sun.xml.parser.ValidatingParser</CODE>),         and entity resolver. The fully qualified name of either parser can be         sent to the parser factory to obtain an instance of that parser. The nonvalidating         parser generates errors if a document is not well formed, and does some         processing of the DTD (if present) but does not check to make sure that         the document obeys all of the constraints defined by the DTD. The validating         parser, on the other hand, checks to make sure that the document obeys         all such constraints.</TD>    </TR>  </TABLE>  <BLOCKQUOTE>     <P><B>Technical Note: </B><BR>      All nonvalidating parsers are not created equal! Although a validating parser       is required to process <I>all</I> external entities referenced from within       the document, some of that processing is optional for a nonvalidating parser.       With such a parser, an externally stored section of the DTD that is &quot;included&quot;       in the current document using an entity reference might not be processed.       In addition, a nonvalidating parser is not required to identify ignorable       whitespace (although a validating parser must). In that case, whitespace       which can legitimately be ignored would be returned as part of the normal       character stream. The nonvalidating parser in Sun's Java XML library implements       both of these optional behaviors -- it processes all external entities and       it identifies ignorable whitespace. </P>  </BLOCKQUOTE>  <H4>Other SAX Interfaces</H4>  <P>In addition to the APIs described <A name=DIFF22></A><A href=#DIFF23><IMG src=../diffpics/oold.gif></A><STRIKE>in the overview section, </STRIKE><A name=DIFF22></A><A href=#DIFF23><IMG src=../diffpics/onew.gif></A><STRONG><I>here, </STRONG></I>the SAX APIs define a few other interfaces   that you are likely to use when you write a SAX application, as well as a utility   package with a number of classes that are helpful for building real-world applications.   When you are ready for a bit more information pertaining to SAX, go <A name=DIFF23></A><A href=#DIFF24><IMG src=../diffpics/oold.gif></A><STRIKE>here for Other SAX APIs . </STRIKE><A name=DIFF23></A><A href=#DIFF24><IMG src=../diffpics/onew.gif></A><STRONG><I>here: <A HREF=3_apis_addlSAX.html>3b.   Other SAX APIs</A>.</STRONG></I></P>  <BLOCKQUOTE>     <P></P>  </BLOCKQUOTE><BLOCKQUOTE>   <BLOCKQUOTE>     <P></P>  </BLOCKQUOTE></BLOCKQUOTE><H3><A NAME=DOM></A>The Document Object Model (DOM) <A name=DIFF24></A><A href=#DIFF25><IMG src=../diffpics/onew.gif></A><STRONG><I>APIs</STRONG></I></H3><A name=DIFF25></A><A href=#DIFF26><IMG src=../diffpics/oold.gif></A><STRIKE>The diagram below shows how Sun's Java XML libraries implement the Document Object Model. </STRIKE><P><A name=DIFF26></A><A href=#DIFF27><IMG src=../diffpics/onew.gif></A><STRONG><I>The diagram below shows the JAXP APIs in action:</STRONG></I></P><BLOCKQUOTE>   <P><A name=DIFF27></A><A href=#DIFF28><IMG src=../diffpics/onew.gif></A><STRONG><I><IMG SRC=images/dom-api.gif WIDTH=439 HEIGHT=454></STRONG></I></P></BLOCKQUOTE><P><A name=DIFF28></A><A href=#DIFF29><IMG src=../diffpics/oold.gif></A><STRIKE>The XmlDocumentBuilder class implements the SAX DocumentHandler interface. An instance of this class is handed to one of the SAX parsers ( Parser or ValidatingParser ). The parser's parse method is then invoked on an input source, loading up the XmlDocumentBuilder object. That object's getDocument() method then returns an instance of XmlDocument . </STRIKE><A name=DIFF28></A><A href=#DIFF29><IMG src=../diffpics/onew.gif></A><STRONG><I>You use the <CODE>javax.xml.parsers.</CODE>DocumentBuilderFactory class to   get a DocumentBuilder instance (upper left), and use that to produce a Document   (a DOM) that conforms to the DOM specification (lower right). The builder you   get, in fact, is determined by the System property, <TT>javax.xml.parsers.DocumentBuilderFactory</TT>,   which selects the factory implementation that is used to produce the builder.   (The platform's default value can be overridden from the command line.) </STRONG></I></P>  <P><A name=DIFF29></A><A href=#DIFF30><IMG src=../diffpics/onew.gif></A><STRONG><I>You can use the builder's <CODE>newDocument()</CODE> method to create an empty   Document that implements the <A HREF=../../api/org/w3c/dom/Document.html>org.w3c.dom.Document</A>   interface. Alternatively, you can use one of the builder's parse methods to   create a Document from existing XML data. The result is a DOM tree like that   shown in the lower right corner of the diagram.</STRONG></I></P>  <H4><A NAME=DomPackages></A>Packages</H4>  <P>The Document Object Model implementation is defined in the following packages:</P>  <TABLE WIDTH=92% BORDER=1>    <TR>       <TD WIDTH=22%><B><I>Package</I></B></TD>      <TD WIDTH=78%><B><I>Description</I></B></TD>    </TR>    <TR>       <TD WIDTH=22%><A HREF=../../api/org/w3c/dom/package-summary.html>org.w3c.dom</A>       </TD>      <TD WIDTH=78%>Defines the DOM programming interfaces for XML (and, optionally,         HTML) documents, as specified by the W3C.</TD>    </TR>    <TR>       <TD WIDTH=22%><A name=DIFF30></A><A href=#DIFF31><IMG src=../diffpics/onew.gif></A><STRONG><I><A HREF=../../api/javax/xml/parsers/package-frame.html>javax.xml.parsers</A></TD>          <TD WIDTH=78%>Defines the DocumentBuilderFactory class and the DocumentBuilder       class, which returns an object that implements the W3C Document interface.       The factory that is used to create the builder is determined by the <TT>javax.xml.parsers</TT>       system property, which can be set from the command line or overridden when       invoking the <CODE>newInstance</CODE> method. This package also defines       the <CODE>ParserConfigurationException</CODE> class for reporting errors.</STRONG></I></TD>    </TR>    <TR>       <TD WIDTH=22%>         <P><A HREF=../../api/com/sun/xml/tree/package-summary.html>com.sun.xml.tree</A>         </P>      </TD>      <TD WIDTH=78%>         <P>Sun's Java XML implementation of the DOM libraries, including the <CODE>XmlDocument</CODE>,           <CODE>XmlDocumentBuilder</CODE>, and <CODE>TreeWalker</CODE> classes.         </P>      </TD>    </TR>  </TABLE><H3><A name=DIFF31></A><A href=#DIFF32><IMG src=../diffpics/onew.gif></A><STRONG><I><A NAME=ProjectX></A>The Project X Reference Implementation</H3><P>This section shows how the reference implementation combines the SAX and DOM   APIs. </P><BLOCKQUOTE>   <P><IMG SRC=../images/sun.gif WIDTH=62 HEIGHT=29> <B>Note:</B><BR>    The material in the remainder of this section is specific to Project X, Sun's 

⌨️ 快捷键说明

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