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

📄 0290-0293.html

📁 Presenting XML.rar,详细介绍有关XML的知识
💻 HTML
字号:
<!DOCTYPE HTML PUBLIC "html.dtd"><HTML><HEAD><TITLE>Presenting XML:Automating the Web: Rapid Integration with XML:EarthWeb Inc.-</TITLE><META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW"><SCRIPT><!--function displayWindow(url, width, height) {        var Win = window.open(url,"displayWindow",'width=' + width +',height=' + height + ',resizable=1,scrollbars=yes');}//--></SCRIPT></HEAD><BODY  BGCOLOR="#FFFFFF" VLINK="#DD0000" TEXT="#000000" LINK="#DD0000" ALINK="#FF0000"><TD WIDTH="540" VALIGN="TOP"><!--  <CENTER><TABLE><TR><TD><FORM METHOD="GET" ACTION="http://search.itknowledge.com/excite/cgi-bin/AT-foldocsearch.cgi"><INPUT NAME="search" SIZE="20" VALUE=""><BR><CENTER><INPUT NAME="searchButton" TYPE="submit" VALUE="Glossary Search"></CENTER><INPUT NAME="source" TYPE="hidden" VALUE="local" CHECKED> <INPUT NAME="bltext" TYPE="hidden" VALUE="Back to Search"><INPUT NAME="sp" TYPE="hidden" VALUE="sp"></FORM></TD><TD><IMG SRC="http://www.itknowledge.com/images/dotclear.gif" WIDTH="15"   HEIGHT="1"></TD><TD><FORM METHOD="POST" ACTION="http://search.itknowledge.com/excite/cgi-bin/AT-subscriptionsearch.cgi"><INPUT NAME="search" SIZE="20" VALUE=""><BR><CENTER><INPUT NAME="searchButton" TYPE="submit" VALUE="  Book Search  "></CENTER><INPUT NAME="source" TYPE="hidden" VALUE="local" CHECKED> <INPUT NAME="backlink" TYPE="hidden" VALUE="http://search.itknowledge.com:80/excite/AT-subscriptionquery.html"><INPUT NAME="bltext" TYPE="hidden" VALUE="Back to Search"><INPUT NAME="sp" TYPE="hidden" VALUE="sp"></FORM></TD></TR></TABLE></CENTER> --><!--  ISBN=1575213346 //--><!--  TITLE=Presenting XML//--><!--  AUTHOR=Richard Light//--><!--  PUBLISHER=Macmillan Computer Publishing//--><!--  IMPRINT=Sams//--><!--  CHAPTER=15 //--><!--  PAGES=0283-0300 //--><!--  UNASSIGNED1 //--><!--  UNASSIGNED2 //--><P><CENTER><A HREF="0287-0289.html">Previous</A> | <A HREF="../ewtoc.html">Table of Contents</A> | <A HREF="0294-0297.html">Next</A></CENTER></P><A NAME="PAGENUM-290"><P>Page 290</P></A><P>My organization, webMethods, has employed XML to implement a WebInterface Definition Language (WIDL) directed at these needs. Theremainder of this section examines WIDL's workings as an example of how XML canbe used to automate the Web.</P><H4><A NAME="ch15_ 8">Describing the Functionality of the Web</A></H4><P>In much the same way that Channel Definition Format (CDF) seeks toprovide a metadata language that allows Web sites to be described as contentfor push channels, the Web Interface Definition Language seeks to enablethe functionality of Web sites to be described to remote systems.</P><P>The concept of an Interface Definition Language (IDL)is not new. IDLs exist for many middleware technologies. For instance, an IDL for CORBA(Common Object Request Broker Architecture) describes interfaces toCORBA objects that live in a distributed environment.</P><P>The Web Interface Definition Language describes business objects on theWeb, defining an API to services (such as CGI scripts) that reside behind Web <BR>documents.</P><H4><A NAME="ch15_ 9">Processing Documents</A></H4><P>At the highest level, WIDL describes the location (URL) of services, theinput parameters to be submitted (via GET or POST methods) to each service, andthe output parameters to be returned by each service. This last requirementimplies a capability to reliably extract specific data elements from Webdocuments and map them to output parameters.</P><P>Two candidate technologies for data extraction arepattern matching and parsing. Pattern matching extracts data based on regular expressions, and it iswell suited to raw text files and poorly constructed HTML documents. There isa lot of bad HTML in the world! Parsing, on the other hand, recoversboth document structure and the relationship between document objects.</P><P>From an administrative point of view, pattern matching is more laborintensive for establishing and maintaining relationships between data elementsand program variables. Regular expressions are difficult to construct and moreprone to breakage as document structures change. For instance, the addition offormatting tags around data elements in HTML documents could easily derailthe search for a pattern. An object model, on the other hand, can see throughsuch cosmetic changes.</P><A NAME="PAGENUM-291"><P>Page 291</P></A><P>Patterns must also be carefully constructed to avoid unintentionalmatching. In complex cases, patterns must be nested within patterns. The processof mapping patterns to a number of output parameters thus can becomequite onerous.</P><P>It is possible to achieve the best of both worlds by using pattern matchingwhen necessary to match against the attributes of objects accessible via anObject Model. Using a hybrid model, pattern matching within objects providesfor the extraction of target information from preformatted text regions or text files.</P><H4><A NAME="ch15_ 10">Variable Assignment</A></H4><P>JavaScript introduced a Page Object Model that provided access to a smallset of elements on a page within a browser. More recently the World WideWeb Consortium (W3C) has established a working group to specify astandard Document Object Model (DOM) that makes it possible to address all theelements of both HTML and XML documents.</P><P>A convenient way to access document objects is with an object reference.Here again is the example price list:</P><!--  CODE //--><PRE>  &lt;TABLE&gt;  &lt;TR&gt;&lt;TD&gt;Hammer     &lt;/TD&gt;&lt;TD&gt;12.00&lt;/TD&gt;&lt;TD&gt;50&lt;/TD&gt;&lt;TD&gt;Tom's Tools  &lt;/TD&gt;&lt;/TR&gt;  &lt;TR&gt;&lt;TD&gt;Screwdriver&lt;/TD&gt;&lt;TD&gt;8.00 &lt;/TD&gt;&lt;TD&gt;60&lt;/TD&gt;&lt;TD&gt;Handyman  Hardware&lt;/TD&gt;&lt;/TR&gt;  &lt;TR&gt;&lt;TD&gt;Pliers     &lt;/TD&gt;&lt;TD&gt;10.00&lt;/TD&gt;&lt;TD&gt;35&lt;/TD&gt;&lt;TD&gt;Get A Grip!  &lt;/TD&gt;&lt;/TR&gt;&lt;/TABLE&gt;</PRE><!--  END CODE //--><P>An object reference of table[0].tr[].td[0] returns an array of itemnames. Using object references makes it simple to provide a mapping betweenelements extracted from Web documents and the output parameters defined byWIDL. The XML element to achieve this is defined as follows:</P><!--  CODE //--><PRE>&lt;VARIABLE   NAME='products'            TYPE='string[]'            REFERENCE='doc.table[0].tr[].td[0].value' /&gt;&lt;VARIABLE   NAME='prices'            TYPE='string[]'            REFERENCE='doc.table[0].tr[].td[1].value' /&gt;&lt;VARIABLE   NAME='quantity'            TYPE='string[]'</PRE><!--  END CODE //--><A NAME="PAGENUM-292"><P>PAGE 292</P></A><!--  CODE //--><PRE>	        REFERENCE='doc.table[0].tr[].td[2].value' /&gt;&lt;VARIABLE   NAME='vendor'            TYPE='string[]'            REFERENCE='doc.table[0].tr[].td[3].value' /&gt;</PRE><!--  END CODE //--><P>In this example, each column of the price list is mapped into an arrayvariable, demonstrating how XML metadata can be used to reintroduce structureinto HTML documents.</P><H4><A NAME="ch15_ 11">Interfaces and Services</A></H4><P>An interface is a collection of services. Services, in turn, consist ofvariables that are submitted and variables that are returned. In specifying WIDL,we thus needed to define XML elements for interfaces, services, and variables(both input and output), as well as appropriate attributes for representing theinformation necessary to automate interactions with Web servers.</P><P>Taking the example of the stock quote service I discussed earlier, aprogram that automates the Web processes a`stocks' WIDL to understand that in order to access a`stockQuote' service, it must submit an input parameter`symbol' using the `post' method to<A HREF="%60http://quote.yahoo.com'.">`http://quote.yahoo.com'.</A> WIDL also defines object references to map received Web content into outputparameters, such as `companyName', `stockPrice',`percentChange', and `volume'.</P><P>Additionally, WIDL supports object-oriented interfaces, allowing for thedefinition of multiple instances of `stocks'.</P><P>Given the preceding criteria, the XML for an implementation of the`stocks' interface is written with WIDL as follows:</P><!--  CODE //--><PRE>&lt;WIDL NAME='yahoo' TEMPLATE='stocks'&gt;&lt;SERVICE NAME='stockQuote' <A HREF="url='http://quote.yahoo.com'">URL='http://quote.yahoo.com'</A>METHOD='post' INPUT='quoteInput' OUTPUT='quoteOutput' /&gt;&lt;INPUT NAME='quoteInput'&gt;&lt;VARIABLE NAME='symbol' /&gt;&lt;/INPUT&gt;&lt;OUTPUT NAME='quoteOutput'&gt;&lt;VARIABLE NAME='companyName' REFERENCE='doc.table[2].tr[1].td[2].value' /&gt;&lt;VARIABLE NAME='stockPrice' REFERENCE='doc.table[2].tr[2].td[2].value' /&gt;&lt;VARIABLE NAME='percentChange' REFERENCE='doc.table[2].tr[3].td[2].value' /&gt;&lt;VARIABLE NAME='volume'REFERENCE='doc.table[2].tr[4].td[2].value' /&gt;&lt;/OUTPUT&gt;&lt;/WIDL&gt;</PRE><!--  END CODE //--><A NAME="PAGENUM-293"><P>Page 293</P></A><P>WIDL is parsed in the same manner as Web documents to extract therelevant information about the services it provides. For instance, an array ofavailable services for a given WIDL file is retrieved with this simple object reference:</P><!--  CODE SNIP //--><PRE>widl.service[].name</PRE><!--  END CODE SNIP //--><P>The URL and method for each service, the input and output variables,and the object references for output variables are retrieved in a similar fashion.</P><H4><A NAME="ch15_ 12">Automated Applications</A></H4><P>After defining a WIDL file for a given Web service, you can generateapplication-level functions or methods that are insulated from the specifics of theimplementation of each service. A generated function must include a reference toa WIDL file, a service name, and input and output variable names; it doesnot need to include the specifics of where a service resides (URL), the methodused to invoke the service (POST or GET), or object references used to retrievedata into output variables.</P><P>The specifics of a service's implementation are dynamically retrieved fromthe WIDL file at runtime, thus separating the administration of servicedefinitions from a service's invocation in application code, and insulating applicationsfrom changes in Web-hosted functionality.</P><P>Resolving attribute mappings at runtime enables centralized changemanagement of WIDL files as well as the use of naming services to providelocation transparency. In other words, both the location and structure of Webdocuments can change without affecting applications utilizing their services.Application functions can even be remapped to equivalent functionalityelsewhere on the Web.</P><P>From the `stocks' WIDL, it is possible to generate a Javaclass `stockQuote.java'. Java developers can simply include this class in theirapplications, accessing the stockQuote service with a single line of code:</P><!--  CODE SNIP //--><PRE>stockQuote myQuote = new stockQuote(&quot;SUNW&quot;);</PRE><!--  END CODE SNIP //--><P>The Java class encapsulates an understanding of how to locate andinterpret the `stocks' WIDL, pass the input parameters to the appropriate Webservice, and return the expected data to the calling program.</P><P>If for some reason the Yahoo stock service is unavailable, the WIDL canbe used to transparently redirect this request to the CNN Financial Network.</P><P><CENTER><A HREF="0287-0289.html">Previous</A> | <A HREF="../ewtoc.html">Table of Contents</A> | <A HREF="0294-0297.html">Next</A></CENTER></P></TD></TR></TABLE></BODY></HTML>

⌨️ 快捷键说明

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