圆月山庄资源网 Design By www.vgjia.com
This script demonstrates how to save information to a xml file with the use of MSXML. The example xml file is used for the photo album on the site.
复制代码 代码如下:
'*****************************************************************
'** Script: CreateXML.vbs
'** Version: 1.0
'** Created: 01/12/2009 9:51PM
'** Author: Adriaan Westra
'** E-mail:
'** Purpose / Comments:
'** Create xml file for photo album
'**
'**
'** Changelog :
'** 12-01-2009 9:51 : Initial version
'**
'*****************************************************************
On Error Resume next
Dim Version : Version = "1.0" ' Script version
Dim Author : Author = "A. Westra"
Dim objXML 'XML Document object
Dim root 'Root element of the xml document
Dim newNode ' XML Node object
Dim cNode ' XML (child) Node object
Dim cNodeText ' XML Text Node object
'*****************************************************************
'** Make sure the script is started with cscript
If InStr(wscript.FullName, "wscript.exe") > 0 Then
MsgBox "Please run this script with cscript.exe." & Chr(13) & _
"For example : cscript " & WScript.ScriptName & " /?", _
vbExclamation, WScript.ScriptName
WScript.Quit(1)
End If
'*****************************************************************
'** Get commandline parameters
Set Args = Wscript.Arguments
If Args.Count = 0 Then
strImageDir = InputBox("Please give the directory name " & _
"to process : ",wscript.scriptname, strPath)
Else
If InStr(Args(0),"/?") > 0 Or InStr(UCase(Args(0)),"/H") > 0 _
Or InStr(UCase(Args(0)),"/HELP") > 0 Then
DisplayHelp
Wscript.quit(0)
Else
strImageDir = Args(0)
End if
End if
Set objXML = CreateObject("Msxml2.DOMDocument.6.0")
objXML.setProperty "SelectionLanguage", "XPath"
'*****************************************************************
'** Determine if the file exists
strXMLFile = strImageDir & "\album.xml"
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(strXMLFile) Then
'*****************************************************************
'** Read the XML File
objXML.load(strXMLFile)
Else
'*****************************************************************
'** Create the XML File
objXML.loadXML("")
End If
'*****************************************************************
'** Process directory
Set objImgDir = objFSO.GetFolder(strImageDir)
For each objFile in objImgDir.Files
If IsJPG(objFile.Name) Then
arrTemp = split(objFile.Name, ".")
strNode = arrTemp(0)
'*****************************************************************
'** Determine if the node exists
If Not XmlNodeExists(strChildNode, objXML) Then
'*****************************************************************
'** Get the root element of the xml document
Set root = objXML.documentElement
'*****************************************************************
'** Create the new node
Set newNode = objXML.createNode(1, strNode, "")
root.appendChild newNode
Set cNode = objXML.createNode(1, "alt", "")
Set cNodeText = objXML.createNode(3, "", "")
cNodeText.Text = strNode
cNode.appendChild cNodeText
newNode.appendChild cNode
Set cNode = objXML.createNode(1, "Title", "")
Set cNodeText = objXML.createNode(3, "", "")
cNodeText.Text = strNode
cNode.appendChild cNodeText
newNode.appendChild cNode
End If
End If
Next
'*****************************************************************
'** Save the xml file
objXML.save(strXMLFile)
'*****************************************************************
'** End the script
wscript.quit
'*****************************************************************
'** Function: XmlNodeExists
'** Version: 1.0
'** Created: 1/12/2009 12:14PM
'** Author: Adriaan Westra
'** E-mail:
'**
'** Purpose / Comments:
'** Determines if a node exists in XML
'**
'** Arguments :
'** strNode :Name of the XML node
'** oXML :XMl DOM Object
'**
'** Changelog :
'** 1/12/2009 12:16PM : Initial version
'**
'*****************************************************************
Function XmlNodeExists( strNode, oXML )
On Error Resume next
Set oNode = oXML.selectSingleNode(strNode)
strNodetype = oNode.nodetype
If err.number = 0 Then
XmlNodeExists = True
Else
XmlNodeExists = False
End if
End Function
'*****************************************************************
'** Sub: DisplayHelp
'** Version: 1.0
'** Created: 24-03-2003 8:22
'** Author: Adriaan Westra
'** E-mail:
'**
'** Purpose / Comments:
'** Display help for script
'**
'** Arguments :
'**
'** Wijzigingslog :
'** 24-03-2003 8:22 : Initi雔e versie
'**
'*****************************************************************
Sub DisplayHelp()
strComment = string(2,"*")
strCmntLine = String(79, "*")
wscript.echo strCmntline
wscript.echo strComment
wscript.echo strComment & " Online help for " & _
Wscript.scriptname & " version : " & Version
wscript.echo strComment
wscript.echo strComment & " Usage : cscript " & _
Wscript.scriptname & " directoryname"
wscript.echo strComment
wscript.echo strComment & " Purpose : Create XML file " & _
"for all images in given directory."
wscript.echo strComment
wscript.echo strComment & " Author : " & Author
wscript.echo strComment & " E-mail : " & Email
wscript.echo strComment
wscript.echo strCmntline
End Sub
'*****************************************************************
'** Function: IsJPG
'** Version: 1.0
'** Created: 12/29/2008 11:01PM
'** Author: Adriaan Westra
'** E-mail:
'**
'** Purpose / Comments:
'** Determine if file is jpg image
'**
'** Arguments :
'** strFilename : name of the file to check
'**
'** Wijzigingslog :
'** 12/29/2008 11:02PM : Initi雔e versie
'**
'*****************************************************************
Function IsJPG(strFilename)
Set objRegExp = New RegExp
objRegExp.Pattern = "\w.jpg"
objRegExp.IgnoreCase = True
IsJPG = objRegExp.Test(strFileName)
End Function
复制代码 代码如下:
'*****************************************************************
'** Script: CreateXML.vbs
'** Version: 1.0
'** Created: 01/12/2009 9:51PM
'** Author: Adriaan Westra
'** E-mail:
'** Purpose / Comments:
'** Create xml file for photo album
'**
'**
'** Changelog :
'** 12-01-2009 9:51 : Initial version
'**
'*****************************************************************
On Error Resume next
Dim Version : Version = "1.0" ' Script version
Dim Author : Author = "A. Westra"
Dim objXML 'XML Document object
Dim root 'Root element of the xml document
Dim newNode ' XML Node object
Dim cNode ' XML (child) Node object
Dim cNodeText ' XML Text Node object
'*****************************************************************
'** Make sure the script is started with cscript
If InStr(wscript.FullName, "wscript.exe") > 0 Then
MsgBox "Please run this script with cscript.exe." & Chr(13) & _
"For example : cscript " & WScript.ScriptName & " /?", _
vbExclamation, WScript.ScriptName
WScript.Quit(1)
End If
'*****************************************************************
'** Get commandline parameters
Set Args = Wscript.Arguments
If Args.Count = 0 Then
strImageDir = InputBox("Please give the directory name " & _
"to process : ",wscript.scriptname, strPath)
Else
If InStr(Args(0),"/?") > 0 Or InStr(UCase(Args(0)),"/H") > 0 _
Or InStr(UCase(Args(0)),"/HELP") > 0 Then
DisplayHelp
Wscript.quit(0)
Else
strImageDir = Args(0)
End if
End if
Set objXML = CreateObject("Msxml2.DOMDocument.6.0")
objXML.setProperty "SelectionLanguage", "XPath"
'*****************************************************************
'** Determine if the file exists
strXMLFile = strImageDir & "\album.xml"
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(strXMLFile) Then
'*****************************************************************
'** Read the XML File
objXML.load(strXMLFile)
Else
'*****************************************************************
'** Create the XML File
objXML.loadXML("")
End If
'*****************************************************************
'** Process directory
Set objImgDir = objFSO.GetFolder(strImageDir)
For each objFile in objImgDir.Files
If IsJPG(objFile.Name) Then
arrTemp = split(objFile.Name, ".")
strNode = arrTemp(0)
'*****************************************************************
'** Determine if the node exists
If Not XmlNodeExists(strChildNode, objXML) Then
'*****************************************************************
'** Get the root element of the xml document
Set root = objXML.documentElement
'*****************************************************************
'** Create the new node
Set newNode = objXML.createNode(1, strNode, "")
root.appendChild newNode
Set cNode = objXML.createNode(1, "alt", "")
Set cNodeText = objXML.createNode(3, "", "")
cNodeText.Text = strNode
cNode.appendChild cNodeText
newNode.appendChild cNode
Set cNode = objXML.createNode(1, "Title", "")
Set cNodeText = objXML.createNode(3, "", "")
cNodeText.Text = strNode
cNode.appendChild cNodeText
newNode.appendChild cNode
End If
End If
Next
'*****************************************************************
'** Save the xml file
objXML.save(strXMLFile)
'*****************************************************************
'** End the script
wscript.quit
'*****************************************************************
'** Function: XmlNodeExists
'** Version: 1.0
'** Created: 1/12/2009 12:14PM
'** Author: Adriaan Westra
'** E-mail:
'**
'** Purpose / Comments:
'** Determines if a node exists in XML
'**
'** Arguments :
'** strNode :Name of the XML node
'** oXML :XMl DOM Object
'**
'** Changelog :
'** 1/12/2009 12:16PM : Initial version
'**
'*****************************************************************
Function XmlNodeExists( strNode, oXML )
On Error Resume next
Set oNode = oXML.selectSingleNode(strNode)
strNodetype = oNode.nodetype
If err.number = 0 Then
XmlNodeExists = True
Else
XmlNodeExists = False
End if
End Function
'*****************************************************************
'** Sub: DisplayHelp
'** Version: 1.0
'** Created: 24-03-2003 8:22
'** Author: Adriaan Westra
'** E-mail:
'**
'** Purpose / Comments:
'** Display help for script
'**
'** Arguments :
'**
'** Wijzigingslog :
'** 24-03-2003 8:22 : Initi雔e versie
'**
'*****************************************************************
Sub DisplayHelp()
strComment = string(2,"*")
strCmntLine = String(79, "*")
wscript.echo strCmntline
wscript.echo strComment
wscript.echo strComment & " Online help for " & _
Wscript.scriptname & " version : " & Version
wscript.echo strComment
wscript.echo strComment & " Usage : cscript " & _
Wscript.scriptname & " directoryname"
wscript.echo strComment
wscript.echo strComment & " Purpose : Create XML file " & _
"for all images in given directory."
wscript.echo strComment
wscript.echo strComment & " Author : " & Author
wscript.echo strComment & " E-mail : " & Email
wscript.echo strComment
wscript.echo strCmntline
End Sub
'*****************************************************************
'** Function: IsJPG
'** Version: 1.0
'** Created: 12/29/2008 11:01PM
'** Author: Adriaan Westra
'** E-mail:
'**
'** Purpose / Comments:
'** Determine if file is jpg image
'**
'** Arguments :
'** strFilename : name of the file to check
'**
'** Wijzigingslog :
'** 12/29/2008 11:02PM : Initi雔e versie
'**
'*****************************************************************
Function IsJPG(strFilename)
Set objRegExp = New RegExp
objRegExp.Pattern = "\w.jpg"
objRegExp.IgnoreCase = True
IsJPG = objRegExp.Test(strFileName)
End Function
标签:
信息,XML
圆月山庄资源网 Design By www.vgjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
圆月山庄资源网 Design By www.vgjia.com
暂无评论...
更新日志
2024年11月01日
2024年11月01日
- 2024年08月05日
- 柏菲·珞叔作品集《金色大厅2》限量开盘母带ORMCD[低速原抓WAV+CUE]
- NS版《人中之龙 极》演员本宫泰风饰演父亲的广告现已公开!
- 英国女性Switch用户占比达到47% 5年内翻了一番!
- 外媒:《死亡岛2》或是今年PS+2档最受欢迎游戏
- 群星.1997-世纪之歌第二辑6CD【宝丽金】【WAV+CUE】
- 邵萱.1997-是是非非【捷登】【WAV+CUE】
- 巫启贤.1998-我是你的【风格】【WAV+CUE】
- 【原神手游】「月草的赐慧」祈愿
- 【原神手游】「赤团开时」祈愿
- 【原神手游】「法器·千夜浮梦」介绍
- 陈立农《青春为名 上部曲 - 恋》[FLAC/分轨][290.58MB]
- 张乔西《明星》[320K/MP3][55.23MB]
- 张乔西《明星》[FLAC/分轨][143.08MB]
- 《P3R:Episode Aegis》:重复爬塔的悲伤