1

I have a file which is in xml format.

  <fciv>
  -<FILE_ENTRY>
  <name>e:\logs3\database1.txt</name>
  <MD5>0rxJSXF5tCO3pAk3IcSJBA==</MD5>
  </FILE_ENTRY>
  </FCIV>

I want to load this file using vbscript, and save the "name" and "md5" part to a text file.. is it possible? if yes, how to do it? can I get some help?

aefxx
  • 24,835
  • 6
  • 45
  • 55
dante akram
  • 39
  • 2
  • 8
  • 1
    Does this help? http://stackoverflow.com/questions/8254600/reading-xml-file-with-vbscript – Arvind Haran Jul 26 '13 at 05:56
  • ya that is what I wanna do but how do I save it to a txt file after absorbing the parameters of the xml file??? – dante akram Jul 26 '13 at 06:48
  • 1
    When in doubt, read the [documentation](http://msdn.microsoft.com/en-us/library/t5399c99%28v=vs.84%29.aspx). – Ansgar Wiechers Jul 26 '13 at 07:56
  • the documentation part not helping. its not normal writing to a txt file program. I have to extract info from an xml file and save it to a text using vbs – dante akram Jul 26 '13 at 09:15
  • 1
    Arvind Haran pointed you to an answer covering the extraction part. The documentation covers the writing to a file part. Anything else missing? – Ansgar Wiechers Jul 26 '13 at 09:42
  • ya I tried using the syntax and logic identical to the syntax used in the link posted mr arvind but even then the program has errors wen running – dante akram Jul 26 '13 at 12:48
  • WScript.Echo "Port " & port.nodeValue & " has IP address is " & ip.nodeValue when I use the above line, only the text in the "" is being printed but the values (ie values pointed by port.nodevalue and ip.nodevalue is not printed) – dante akram Jul 26 '13 at 12:49
  • So, update your question with the code you currently have, and the error(s) it's raising. – Ansgar Wiechers Jul 27 '13 at 11:17
  • got the answer guys! thanks to both of u! helped me a lot – dante akram Jul 29 '13 at 04:41

1 Answers1

0

This should do it ...

script.vbs

Set xmlDoc = CreateObject("MSXML.DOMDocument")
xmlDoc.Load "input.xml"
Set xmlNodeName = xmlDoc.selectSingleNode("/FCIV/FILE_ENTRY/name")
Set xmlNodeMD5 = xmlDoc.selectSingleNode("/FCIV/FILE_ENTRY/MD5")
Set fso = CreateObject("Scripting.FileSystemObject")
Set file = fso.OpenTextFile("output.txt", 2, True)
file.WriteLine "* name: " & xmlNodeName.Text
file.WriteLine "* MD5: " & xmlNodeMD5.Text

input.xml

<?xml version="1.0"?>
<FCIV>
  <FILE_ENTRY>
    <name>e:\logs3\database1.txt</name>
    <MD5>0rxJSXF5tCO3pAk3IcSJBA==</MD5>
  </FILE_ENTRY>
</FCIV>

remark: XML is cAsE-sEnSiTiVe

output.txt

* name: e:\logs3\database1.txt
* MD5: 0rxJSXF5tCO3pAk3IcSJBA==