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
相关推荐:
ChatGPT已识别但不可用?揭秘背后原因与解决方案!,小狸ai和斑马ai语文
AI软件不用登录,让你的工作更高效轻松,智能ai写作改稿怎么改
文字写作AI生成工具:让创作更简单、更高效
seo网站关键字排名优化,网站seo关键词 ,运动ai
seo需要学会什么编程,seo要会些什么 ,剪映怎样加ai
AI生成网页模板,轻松打造专业网站,ai网格画法
ChatGPT怎么打不开了?揭秘背后的原因与解决方法,ai中打开ai文件丢失
SEO策划:让你的网站迅速脱颖而出的秘诀,seo优化和技巧
SEO重要性与企业互联网发展的必由之路,互联网营销推广平台设计
ChatGPT画布打不开?如何解决这一常见问题?,Ai怎么储存为Ai格式在桌面
AI提供的阅读书目对学生的专业知识有多大帮助,沃奇ai
什么是seo行业,seo是什么职业做什么的 ,ai标题字体效果
SEO单页网站:助力企业在线营销的一站式解决方案,湖南视频网站优化方式
seo网络推广要做什么,seo 网络推广 ,ai少女喝药
ChatGPT破解:让AI打破语言与思维的边界,ai模板vis
什么是seo反连接,网站反链多好还是少好 ,网易ai产品
seo需要懂什么源码,seo需要懂什么源码技术 ,ai 纤维
“洗稿技巧如何让你的文章脱颖而出,轻松提升内容创作水平!”,台州椒江seo企业排名
软件我在AI:改变未来的智能助手
什么是seo优化营销,seo主要优化什么 ,ai绘画国风古韵
为什么选择收录网站是企业在线营销的必备策略,全网营销与推广
SEO优化做什么的?揭秘SEO优化的核心价值与实战应用,ai做金色
seO经理是什么岗位,seo经理招聘 ,ai写作重复被查
SEO而且:打造高效网站流量增长的秘密武器,滨江网站推广营销
ChatGPT手机下载后打不开?可能是这些问题导致的,解决方法在这里!,孤城ai动画
SEO优化与SEM广告:提升品牌曝光与流量的双重利器,ai接回头
SEO努力:提升网站排名的关键策略,网站建设微企动力
SEO监控:精准把握网站排名与优化成效的利器,湖南seo排名商家名单
ChatGPTWindows版本:让AI助手成为你的工作与生活得力助手,Ai相减变形
ChatGPT页面空白不乏登录:让你秒变职场高手与生活智囊,百度ai 腾讯ai
怎么用AI写文章:高效创作的秘诀
SEO怎么做才能提升网站流量与排名?这篇文章给你全攻略,铁岭定制网站推广公司电话
AI免费试用不需要登录:体验智能科技的魅力,轻松开启未来,华为ai身材
文章去AI回归创作的本真之美
优化软件:让电脑性能焕然一新,提升效率的秘密武器,大理网站推广招聘信息最新
AI网页版智能问答,开启智慧沟通新时代,ai梦境档案用不了手柄
ChatGPT:OpenAI的创新之作-一款颠覆传统的语言模型,ai球衣号
SEO到底怎么做?揭秘从零到精通的完整SEO优化攻略,鸟瞰ai
wordpress seo是什么,wordpress建站seo好做吗 ,学习图文ai
seo简报什么意思,seo工作汇报 ,万花筒 ai
用AI写文章:效率与创意的完美结合
SEO获取流量的必杀技:如何通过优化轻松提升网站排名,德州全网营销推广价格
seo需要干什么,seo需要具备什么知识 ,ai梦境档案世岛大宅
创作新时代:自动生成文章AI的魅力与未来
未来科技:AI工具为生活赋能,打造智能未来
为什么要seo排名,为什么要做seo推广 ,AI写作开启创意新世界
ChatGPT登录界面都不显示了?可能是这些原因导致的!,上海小学ai智能课
“多网建站”助力企业跨越发展,开启全新数字化时代,海南网站优化电池
SEO优化是做什么的?让你的网站流量飙升的秘密武器,乳腺癌ai作用机理
seo自己做什么,自己做seo需要花钱吗 ,ai850775