Yo tengo una página donde he estado haciendo pruebas, en la intranet de la compañía donde trabajo, que hace una pequeña búsqueda en google.
La idea es la siguiente.
Pongo un TextBox para meter las palabras a buscar.
Mando la información a una página ASP y allí es donde viene lo interesante.
Hago un Objeto de MSXML y hago load el archivo doGoogleSearch.xml que obtienes cuando te registras en Google para usar su API.
Busco el elemento etiquetado como "q" y le asigno el valor que tiene mi TextBox.
Despues guardo el archivo xml de nuevo en el servidor.
Cuando regreso al cliente, hago 2 objetos XMLHTTPRequest, uno lo hago funcionar con GET para cargar el archivo doGoogleSearch.xml recién modificado, y el segundo es para mandar ese archivo mediante POST al server de Google.
Automáticamente Google regresa un archivo XML con la respuesta, y allí tu te encaagas de procesar ese archivo. Por lo pronto yo unicamente pongo el archivo en un TextArea, pues me interesa ver el archivo que me regresaa y no presisamente mostrar esa información, pero yo creo que lo siguiente sería hacer una XSL y mostar el archivo XML Formateado en el browser.
El código de mi pagina es el siguiente:
Código:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<% Response.CacheControl = "no-cache" %>
<%
XMLLoaded = false
if Request.Form("txtSearch") <> "" then
Set objXML = Server.CreateObject("Microsoft.XMLDOM")
objXML.Async=false
if objXML.Load(Server.MapPath("doGoogleSearch.xml")) then
' Process the XML File
objXML.getElementsByTagName("q").item(0).text = Request.Form("txtSearch")
Response.Write(objXML.getElementsByTagName("q").item(0).text )
objXML.save(Server.MapPath("doGoogleSearch.xml"))
XMLLoaded = true
else
Dim strErrText
strErrText = ""
Dim xPE
' Obtenga el objeto ParseError
Set xPE = objXML.parseError
With xPE
strErrText = "Your XML Document failed to load" & _
" due the following error." & vbCrLf & _
"Error #: " & .errorCode & ": " & xPE.reason & _
"Line #: " & .Line & vbCrLf & _
"Line Position: " & .linepos & vbCrLf & _
"Position In File: " & .filepos & vbCrLf & _
"Source Text: " & .srcText & vbCrLf & _
"Document URL: " & .url
End With
End If
end if
%>
<html>
<head>
<title>Alex's Implementation of Google</title>
<%
if XMLLoaded then
%>
<script type="text/javascript" language="JavaScript">
<!--
function sendXML() {
var req = new ActiveXObject("Microsoft.XMLHTTP");
var req2 = new ActiveXObject("Microsoft.XMLHTTP");
req.open("POST", "http://api.google.com/search/beta2",true);
req.setRequestHeader("Man", "POST http://api.google.com/search/beta2 HTTP/1.1");
req.setRequestHeader("MessageType", "CALL");
req.setRequestHeader("Content-Type", "text/xml");
if (req2) {
req2.onreadystatechange = function() {
if (req2.readyState == 4 && req2.status == 200) {
req.send(req2.responseText);
}
};
}
req2.open('GET', 'http://tomsrtds1/ppts/toms/xmlTest/doGoogleSearch.xml',true);
req2.send(null);
if (req) {
req.onreadystatechange = function() {
if (req.readyState == 4 && req.status == 200) {
document.all.xmlResult.value=req.responseText;
}
};
}
}
function MM_callJS(jsStr) { //v2.0
return eval(jsStr)
}
//-->
</script>
<%
end if
%>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body <%
if XMLLoaded then
%>onLoad="MM_callJS('sendXML();')"
<%
end if
%>>
<h1 align="center"><em>Enter your Search Words </em></h1>
<form name="form1" method="post" action="">
<div align="center">
<p>
<input name="txtSearch" type="text" id="txtSearch">
</p>
<p>
<input name="button" type="submit" id="button" value="Search">
</p>
<p>
<textarea name="xmlResult" cols="100" rows="100" id="xmlResult"></textarea>
</p>
</div>
</form>
<%
If strErrText <> "" then
Response.Write(strErrText)
end if
%>
<p align="center"><em></em></p>
</body>
</html>
El archivo doGoogleXML:
Código:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV: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">Google Acces Key</key>
<q xsi:type="xsd:string">Info loaded from the TextBox</q>
<start xsi:type="xsd:int">0</start>
<maxResults xsi:type="xsd:int">10</maxResults>
<filter xsi:type="xsd:boolean">true</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>
Y la información que he estado leyendo:
http://www.opendirectorysite.net/xmldom/index.htm httpp://www.devguru.com/Technologies...dom_intro.html http://www.scottandrew.com/weblog/articles/dom_1 http://jibbering.com/2002/4/httprequest.html http://www.google.com/apis/index.html
Cabe aclarar que todo este mecánismo es a través del Protocolo SOAP (Simple Object Acces Protocol), algo que se está volviendo muy sonado y que parece ser el protocolo estandar para la comunicación entre aplicaciones web y web services.