[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[转贴] VBScript脚本从XML文件中获取信息

从XML文件中获取信息的vbs代码,这个脚本演示了如何通过MSXML从一个XML文件中的信息。示例XML文件是用于在网站上的相册。此脚本将返回特定图片的标题。

  1. '*****************************************************************
  2. '** Script: getxmlelement.vbs
  3. '** Version: 1.0
  4. '** Created: 1/8/2009 10:58PM
  5. '** Author: Adriaan Westra
  6. '** E-mail:
  7. '** Purpose / Comments:
  8. '** Get an element from a xml file
  9. '**
  10. '**
  11. '** Changelog :
  12. '** 1/8/2009 10:58PM : Initial version
  13. '**
  14. '*****************************************************************
  15. Dim objXML ' object to hold the xml document
  16. Dim objNnode ' xml node object
  17. '*****************************************************************
  18. '** create the xml object
  19. Set objXML = CreateObject("Msxml2.DOMDocument.6.0")
  20. '*****************************************************************
  21. '** Load the xml from file
  22. objXML.load("album.xml")
  23. '*****************************************************************
  24. '** Set language for finding information to XPath
  25. objXML.setProperty "SelectionLanguage", "XPath"
  26. '*****************************************************************
  27. '** Get a reference to the node
  28. Set objNode = objXML.selectSingleNode("/album/DSC_2710/title")
  29. '*****************************************************************
  30. '** Output the requested text
  31. wscript.echo "Title : " & objNode.text
复制代码


The sample xml file used by the script :

  1. <?xml version="1.0"?>
  2. <album>
  3. <title>Bloemen</title>
  4. <DSC_2710>
  5. <alt>Pioenroos</alt>
  6. <title>Pioenroos</title>
  7. </DSC_2710>
  8. <DSC_4777>
  9. <alt>DSC_4777</alt>
  10. <title>DSC_4777</title>
  11. </DSC_4777>
  12. <DSC_4787>
  13. <alt>Vingerhoedskruid</alt>
  14. <title>Vingerhoedskruid</title>
  15. </DSC_4787>
  16. <DSC_4899>
  17. <alt>Lavendel</alt>
  18. <title>Lavendel</title>
  19. </DSC_4899>
  20. <DSC_5003>
  21. <alt>Zonnebloem</alt>
  22. <title>Zonnebloem</title>
  23. </DSC_5003>
  24. </album>
复制代码


转自:http://www.jb51.net/article/29242.htm

返回列表