Google search of WebService articles (2)
Source code
<% @ Page contentType = "text / html; gb2312 charset ="%>
<% @ Page import = "org.apache.xalan.processor.TransformerFactoryImpl"%>
<% @ Page import = "javax.xml.soap.SOAPConnectionFactory"%>
<% @ Page import = "javax.xml.soap.SOAPConnection"%>
<% @ Page import = "javax.xml.soap.MessageFactory"%>
<% @ Page import = "javax.xml.soap.SOAPMessage"%>
<% @ Page import = "javax.xml.soap.SOAPPart"%>
<% @ Page import = "javax.xml.soap.SOAPEnvelope"%>
<% @ Page import = "javax.xml.soap.SOAPBody"%>
<% @ Page import = "javax.xml.soap.SOAPElement"%>
<% @ Page import = "java.io.FileInputStream"%>
<% @ Page import = "javax.xml.transform.stream.StreamSource"%>
<% @ Page import = "javax.xml.messaging.URLEndpoint"%>
<% @ Page import = "javax.xml.transform.TransformerFactory"%>
<% @ Page import = "javax.xml.transform.Transformer"%>
<% @ Page import = "javax.xml.transform.Source"%>
<% @ Page import = "javax.xml.transform.stream.StreamResult"%>
<html>
<head>
<title> Google WebService </ title>
</ Head>
<%
Try (
/ / First establish a connection
SOAPConnectionFactory soapConnFactory =
SOAPConnectionFactory.newInstance ();
SOAPConnection connection =
SoapConnFactory.createConnection ();
/ / Next, create news
MessageFactory messageFactory = MessageFactory.newInstance ();
SOAPMessage message = messageFactory.createMessage ();
/ / Create some news for SOAP object
SOAPPart soapPart = message.getSOAPPart ();
/ / Assembly of information, according to Pan-gen C search.msg document directory search
StreamSource preppedMsgSrc = new StreamSource (new FileInputStream ( "/ search.msg"));
SoapPart.setContent (preppedMsgSrc);
/ / Retention news
Message.saveChanges ();
/ / Sent to the target address
URLEndpoint destination =
New URLEndpoint ( "http://api.google.com/search/beta2");
/ / Send message
SOAPMessage reply = connection.call (message, destination);
/ / Output preservation, the establishment of informationä¼ å‡º
= TransformerFactory transformerFactory
TransformerFactory.newInstance ();
/ / Document forms the basis for analytic translate.xsl
Source styleSheet = new StreamSource ( "/ translate.xsl");
Transformer transformer =
TransformerFactory.newTransformer (styleSheet);
/ / Received from the content of
Source sourceContent = reply.getSOAPPart (). GetContent ();
/ / Create output files results.out
StreamResult result = new StreamResult ( "/ results.out");
Transformer.transform (sourceContent, result);
Out.println ( "document has been generated C: \ results.out");
/ / Close the connection
Connection.close ();
) Catch (Exception e) (
System.out.println (e.getMessage ());
)
%>
</ Body>
</ Html>
Part of the source code in full accordance with the provisions of the preparation of Google, which is also part of procedure notes, here is not a wordy.
Search format
<? Xml version ='1 .0 'encoding =' UTF-8 '?>
<ENV-SOAP: Envelope
Xmlns: SOAP-ENV = "http://schemas.xmlsoap.org/soap/envelope/"
Xmlns: xsi = "http://www.w3.org/1999/XMLSchema-instance"
Xmlns: xsd = "http://www.w3.org/1999/XMLSchema">
<SOAP-ENV:Body>
<Ns1: doGoogleSearch xmlns: ns1 = "urn: GoogleSearch"
SOAP-ENV: encodingStyle = "http://schemas.xmlsoap.org/soap/encoding/">
<key Xsi:type="xsd:string"> 00000000000000000000000000000000 </ key>
<q Xsi:type="xsd:string"> CSDN Forum </ q>
<start Xsi:type="xsd:int"> 0 </ start>
<maxResults Xsi:type="xsd:int"> 10 </ maxResults>
<filter Xsi:type="xsd:boolean"> false </ filter>
<restrict Xsi:type="xsd:string"> </ restrict>
<safeSearch Xsi:type="xsd:boolean"> false </ safeSearch>
<lr Xsi:type="xsd:string"> </ lr>
<ie Xsi:type="xsd:string"> latin1 </ ie>
<oe Xsi:type="xsd:string"> latin1 </ oe>
</ Ns1: doGoogleSearch>
</ SOAP-ENV: Body>
</ SOAP-ENV: Envelope>
Search.msg paper labels <<key> </ key> before a fixed format, without bother. Tags <key> is the first part of this paper, the reference to "license key," the direct copying from. Tags <q> means to search for specific content. Tags <start> refers to several start from the search. Tags <maxResults> refers to each of the maximum return to the search results, Google WebService, Max is only "10." Tags <filter> refers to filter out results and domain names similar to the same result. Tags <restrict> refers to the theme of national and restraint, for example, should be restricted only in the domestic search, we need input countryCN; Linux should be restricted only in the search theme, on the importation of linux. Tags <safeSearch> filter out adult information. Tags <lr> language search, such as search only Simplified Chinese, it is necessary to input lang_zh-CN. Tags <oe ie> and <> respectively, input and output encoding format defaults to latin1 (UTF-8).
Analysis format
<? Xml version = "1.0">
<xsl:stylesheet Version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output Method="text"/>
<xsl:template Match="/">
<xsl:apply-templates Select="//item"/>
</ Xsl: template>
<xsl:template Match="item">
<xsl:value-of Select="title" disable-output-escaping="yes"/>
<xsl:text>
</ Xsl: text>
<xsl:value-of Select="URL"/>
<xsl:text>
</ Xsl: text>
<xsl:value-of Select="summary"/>
</ Xsl: template>
</ Xsl: stylesheet>
Translate.xsl document. We <xsl: value-of select = "title" disable-output-escaping = "yes" /> This one, select = "title" to return to determine the outcome of the first part of the title. Next, select = "URL" Analysis of the URL address. <xsl:text> </ Xsl: text> for the time being understood as to label it. Select = "summary" Analysis of the summary. Some label, the details please refer to the "Google Web APIs Reference."
Postscript
Running after the results results.out please you to read, not enumerated in the here.
The purpose of this article created purely personal hobbies, and completely engine Google is a favorite. The article is not very deep, you can hope that the role playedæŠ›ç –å¼•çŽ‰I meet, there are more rich features that we can to explore!
Tags: google, webservice








0 Comments to “Google search of WebService articles (2)”
No Comments. Send your comment.
Leave a Reply
You must be logged in to post a comment.