ASP Examples

ChilkatHOMEAndroid™ASPVisual BasicVB.NETC#iOS (IPhone)Objective-CC++CMFCDelphiFoxProJavaPerl
PHP ExtensionPHP ActiveXPythonPowerShellRubySQL ServerVBScript

ASP Examples

ASP String
ASP Byte Array
Bounced Mail
Bz2
Character Encoding
CSV
Digital Certificates
Digital Signatures
Email
FTP
HTML Conversion
HTTP
IMAP
Encryption
MHT / HTML Email
POP3
RSA
S/MIME
SMTP
Socket
Spider
SSH
SSH Tunnel
SSH Key
SFTP
Tar
ASP Upload
XML
XMP
Zip Compression

More Examples...
Amazon S3
Email Object
DKIM / DomainKey
NTLM
DH Key Exchange
DSA
FileAccess
RSS
Atom
Self-Extractor
Service
PPMD
Deflate
Bzip2
LZW

 

 

 

 

 

 

Add Google Search to Big5 Chinese ASP Page

Download Chilkat XML ActiveX

Download Chilkat Charset ActiveX

ASP example code showing how to use the Google Search API and convert the utf-8 XML response to Big5 for display on a Chinese ASP page. The same code can be used for GB2312. Replace "Big5" with "GB2312" and replace "lang_zh-CN" with "lang_zh-TW".

<%@ LANGUAGE="VBSCRIPT" %>
<html>

<head>
<meta HTTP-EQUIV="Content-Type" CONTENT="text/html;CHARSET=Big5">
<title>Sample Chinese Google Search</title>
</head>

<body bgcolor="#FFFFFF">

<% 

Dim GoogleUrl,GoogleKey,SoapText,ObjXml,UnicodeResponse,CXml

' Get a key from Google...
GoogleKey = "000000000000000000000000000000000000"

' Create a SOAP message for a Google Search Request
' The language is set to Chinese
SoapText = "<?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"">"&GoogleKey&"</key>" & _
"      <q xsi:type=""xsd:string"">Chinese newspaper</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"">lang_zh-CN</lr>" & _
"      <ie xsi:type=""xsd:string"">latin1</ie>" & _
"      <oe xsi:type=""xsd:string"">latin1</oe>" & _
"    </ns1:doGoogleSearch>" & _
"  </SOAP-ENV:Body>" & _
"</SOAP-ENV:Envelope>"

GoogleUrl = "http://api.google.com/search/beta2"  

' Make the SOAP Google API Call
Set ObjXml = CreateObject("Microsoft.XMLHTTP") 
ObjXml.open "POST",GoogleUrl,"False" 
ObjXml.setRequestHeader "Man", "POST"+" "+GoogleUrl+" HTTP/1.1"  
ObjXml.setRequestHeader "MessageType", "CALL"  
ObjXml.setRequestHeader "Content-Type", "text/xml"  
ObjXml.send SoapText  

' Get the Google Search Response
' Google requests and responses are always utf-8.
' However, when the Microsoft.XMLHTTP object returns the response
' text, it is already converted to a Unicode string.
UnicodeResponse = objXML.responseText 
Set ObjXml = Nothing 

' Create a Chilkat ASP XML object for easy parsing.
' ASP XML is a free ASP component from Chilkat Software.
set CXml = Server.CreateObject("Chilkat.Xml")
CXml.LoadXml UnicodeResponse

' This page requires Big5
' Create a Chilkat Charset Conversion component for conversion from Unicode
' The Chilkat Charset component is not a free component, and can
' be licenced from Chilkat Software, Inc.
set cc = Server.CreateObject("Chilkat.Charset2")

' Any value passed to UnlockComponent begins the 30-day trial.
cc.UnlockComponent "30-day trial"
cc.ToCharset = "Big5"

' Quickly navigate to the result elements.
set resultElements = CXml.SearchForTag(Nothing,"resultElements")
if not (resultElements is nothing) then

	' Find the first item
	set item = resultElements.SearchForTag(Nothing,"item")

	while not (item is nothing)
	
		Response.Write "Title: " 
		title = item.GetChildContent("title")
		if Len(title) > 0 then
			Response.BinaryWrite cc.ConvertFromUnicode(title)
		end if
		Response.Write "<br>"
		
		Response.Write "URL: " & item.GetChildContent("URL") & "<br>"

		Response.Write "Summary: " 
		summary = item.GetChildContent("summary")
		if Len(summary) > 0 then
			Response.BinaryWrite cc.ConvertFromUnicode(summary)
		end if
		Response.Write "<br><br>"
		
		set item = item.NextSibling()
	wend
else
	Response.Write CXml.GetXml()
end if

%>

</body>
</html>
 

© 2000-2012 Chilkat Software, Inc. All Rights Reserved.