XMLHttp -> DOMDocument -> MDB


  XMLは、加工の為いったんローカルに保存しています




TargetList.txt には、対象の XML の名前のリストが入っています

  

Dim strBreak,strInsertA,strInsertB,nCnt

' **********************************************************
' Object 作成
' **********************************************************
Set Stream = CreateObject( "ADODB.Stream" )
Set Stream2 = CreateObject( "ADODB.Stream" )
Set Fso = CreateObject( "Scripting.FileSystemObject" )
Set objXMLHttp = CreateObject("Msxml2.ServerXMLHTTP.3.0" )
Set objXML = CreateObject("Msxml2.DOMDocument.3.0")
Set Cn = CreateObject( "ADODB.Connection" )
Set Rs = CreateObject( "ADODB.Recordset" )
Set WshShell = CreateObject( "WScript.Shell" )

strTarget = WshShell.CurrentDirectory & "\" & "budget.mdb"

ConnectionString = _
	"Provider=Microsoft.Jet.OLEDB.4.0;" & _
	"Data Source=" & strTarget & ";"

on error resume next
Cn.Open ConnectionString
if Err.Number <> 0 then
	WScript.Echo Err.Description
	Wscript.Quit
end if
on error goto 0

Cn.Execute "delete from 初期"

strTargetUrl = "対象 URL"
strOut = ""

Set objHandle = Fso.OpenTextFile( "TargetList.txt", 1 )
Do While not objHandle.AtEndOfStream
	strBuffer = objHandle.ReadLine
	strBreak = ""
	Call CreateData( strBuffer )
Loop
objHandle.Close

Cn.Close

WScript.Echo "処理終了"

' **********************************************************
' XML データ作成
' **********************************************************
Function CreateData( strTargetName )

	strRequest = strTargetUrl & strTargetName & ".xml"

	Call objXMLHttp.Open( "GET", strRequest, False )
	objXMLHttp.Send


	' バイナリ保存
	Stream.Open
	Stream.Type = 1	' バイナリ
	Stream.Write objXMLHttp.responseBody
	Stream.SaveToFile "Shift_Jis_Page.txt", 2
	Stream.Close


	' 単純 XML に加工
	Set InObj = Fso.OpenTextFile( "Shift_Jis_Page.txt", 1 )
	Set OutObj = Fso.OpenTextFile( "Shift_Jis_Page2.txt", 2, True )

	nCnt = 0
	Do While not InObj.AtEndOfStream
		Buffer = InObj.ReadLine
		nCnt = nCnt + 1
		select Case nCnt
			Case 1
				OutObj.WriteLine _
				"<?xml version=""1.0"" encoding=""utf-8"" ?>"
			Case 2,3
			Case Else
				OutObj.WriteLine Buffer
		end Select
	Loop

	OutObj.Close
	InObj.Close


	' キャラクタセット変更
	Stream.Open
	Stream.Type = 2		' StreamTypeEnum の adTypeText
	Stream.Charset = "shift_jis"
	Stream.LoadFromFile "Shift_Jis_Page2.txt"
	Stream2.Open
	Stream2.Charset = "utf-8"
	Stream.CopyTo Stream2
	Stream2.SaveToFile strTargetName & ".xml", 2
	Stream2.Close
	Stream.Close


	objXML.load( strTargetName & ".xml" )

	' ルートノードコレクション
	Set objNodeList = objXML.getElementsByTagName("budget")
	strXPath = "body/table/data"
	Set objTarget = objNodeList.Item(0).selectNodes(strXPath)

	on error resume next
	Set objTarget2 = objTarget.Item(1).selectNodes("clm")
	if Err.Number <> 0 then
		MsgBox "対象ノードがありません"
		Exit Function
	end if
	on error goto 0

	For Each obj In objTarget2
		Set objXMLDOMNamedNodeMap = obj.Attributes
		Call InsertData( _
			objXMLDOMNamedNodeMap.getNamedItem("cid").value & "", _
			obj.nodeTypedValue & "" )
	Next
	strInsertA = strInsertA & ")"
	strInsertB = strInsertB & ")"
'	Wscript.Echo  strInsertA & strInsertB
	Cn.Execute strInsertA & strInsertB
	strBreak = ""

End Function

Function InsertData( strKey, strTargetData )

	Dim strData,aData


	if Trim ( strTargetData ) = "" then
		strTargetData = "0"
	end if

	strTargetData = Replace( strTargetData, ",", "" )
	strTargetData = Replace( strTargetData, "△ ", "-" )

	aData = Split( strKey, "-" )
	strData = aData(0) & aData(1)

	if strBreak = "" then
		nCnt = 1
		strInsertA = "insert into 初期 ("
		strInsertB = " values("
		strInsertA = strInsertA & "I" & nCnt
		strInsertB = strInsertB & "'" & strTargetData & "'"
	else
		if strBreak <> strData then

			strInsertA = strInsertA & ")"
			strInsertB = strInsertB & ")"

'			Wscript.Echo  strInsertA & strInsertB
			Cn.Execute strInsertA & strInsertB

			nCnt = 1
			strInsertA = "insert into 初期 ("
			strInsertB = " values("
			strInsertA = strInsertA & "I" & nCnt
			strInsertB = strInsertB & "'" & strTargetData & "'"
		else
			nCnt = nCnt + 1
			strInsertA = strInsertA & ",I" & nCnt
			strInsertB = strInsertB & ",'" & strTargetData & "'"
		end if
	end if

	strBreak = aData(0) & aData(1)

End Function
  











yahoo  google  MSDN  MSDN(us)  WinFAQ  Win Howto  tohoho  ie_DHTML  vector  wdic  辞書  天気 


[smalltech]
CCBot/2.0 (https://commoncrawl.org/faq/)
24/12/06 23:57:55
InfoBoard Version 1.00 : Language=Perl

1 BatchHelper COMprog CommonSpec Cprog CprogBase CprogSAMPLE CprogSTD CprogSTD2 CprogWinsock Cygwin GameScript HTML HTMLcss InstallShield InstallShieldFunc JScript JScriptSAMPLE Jsfuncs LLINK OldProg OracleGold OracleSilver PRO PRObrowser PROc PROconePOINT PROcontrol PROftpclient PROjscript PROmailer PROperl PROperlCHAT PROphp PROphpLesson PROphpLesson2 PROphpLesson3 PROphpfunction PROphpfunctionArray PROphpfunctionMisc PROphpfunctionString PROsql PROvb PROvbFunction PROvbString PROvbdbmtn PROvbonepoint PROwebapp PROwin1POINT PROwinSYSTEM PROwinYOROZU PROwindows ProjectBoard RealPHP ScriptAPP ScriptMaster VBRealtime Vsfuncs a1root access accreq adsi ajax amazon argus asp aspSample aspVarious aspdotnet aw2kinst cappvariety centura ckeyword classStyle cmaterial cmbin cmdbapp cmenum cmlang cmlistbox cmstd cmstdseed cmtxt cs daz3d db dbCommon dbaccess dnettool dos download flex2 flex3 flex4 framemtn framereq freeWorld freesoft gimp ginpro giodownload google hdml home hta htmlDom ie9svg install java javaSwing javascript jetsql jquery jsp jspTest jspVarious lightbox listasp listmsapi listmsie listmsiis listmsnt listmspatch listmsscript listmsvb listmsvc memo ms msde mysql netbeans oraPlsql oracle oracleWiper oraclehelper orafunc other panoramio pear perl personal pgdojo pgdojo_cal pgdojo_holiday pgdojo_idx pgdojo_ref pgdojo_req php phpVarious phpguide plsql postgres ps r205 realC realwebapp regex rgaki ruby rule sboard sc scprint scquest sdb sdbquest seesaa setup sh_Imagick sh_canvas sh_dotnet sh_google sh_tool sh_web shadowbox shgm shjquery shvbs shweb sjscript skadai skywalker smalltech sperl sqlq src systemdoc tcpip tegaki three toolbox twitter typeface usb useXML vb vbdb vbsfunc vbsguide vbsrc vpc wcsignup webanymind webappgen webclass webparts webtool webwsh win8 winofsql wmi work wp youtube