Hi!
When I am using the DOM to read elements of XML files and doing some string manipulation to get of white spaces.
It runs fine with single file but when I try to run on the entire files in a folder, it tells me that it doesn't recognize the xmlDoc object(on xmlDoc.documentElement.nodename and ones there after. then why not two above that line)
I am not sure if this VBS problme or DOM problem.
I am showing you code for one file and entire files.
I am just using vbs to render the entire folder.
I look an can't figure out what is wrong.
Thank you.
Code for single xml file:
' VB Script Document
Set fso = CreateObject("Scripting.FileSystemObject")
'dirpath = InputBox("Path to Directory :")
''set folder=fso.Getfolder(dirpath)
'set files=folder.Files
filename = "CB-000001.xml"
'for each file in files
Set demofile = fso.CreateTextFile("C:\q\xml\dom\cbiac_test.xml")
demofile.WriteLine("<?xml version='1.0' encoding='ISO-8859-1'?>")
set xmlDoc = CreateObject("Microsoft.XMLDOM")
xmlDoc.async="false"
xmlDoc.load(filename)
demofile.WriteLine("<" & xmlDoc.documentElement.nodename & ">")
for each x in xmlDoc.documentElement.childNodes
demofile.Write("<" & x.nodename & ">")
'demofile.WriteLine(x.text)
for each y in x.childNodes
demofile.Write("<" & y.nodename & ">")
'demofile.WriteLine(y.text)
strItem = Split(y.text, " ")
For j = 0 To UBound(strItem)
'MsgBox(strItem(j))
demofile.Write(strItem(j) & " ")
Next
demofile.WriteLine("</" & y.nodename & ">")
next
demofile.WriteLine("</" & x.nodename & ">")
next
demofile.WriteLine("</" & xmlDoc.documentElement.nodename & ">")
'set fso = nothing
'set xmlDoc = nothing
'demofile.close
'next
*********************************
code for the entire files:
' VB Script Document
dim xmlDoc, fso, demofile, docName
Set fso = CreateObject("Scripting.FileSystemObject")
Set xmlDoc = CreateObject("Microsoft.XMLDOM")
dirpath = InputBox("Path to Directory :")
set folder=fso.Getfolder(dirpath)
set files=folder.Files
for each file in files
Set demofile = fso.CreateTextFile("C:\q\xml\dom\cbiac\" & file.name)
demofile.WriteLine("<?xml version='1.0' encoding='ISO-8859-1'?>")
xmlDoc.async="false"
xmlDoc.load(file.name)
demofile.WriteLine("<" & xmlDoc.documentElement.nodename & ">") <<==== here ..telling object required:"documentElement
for each x in xmlDoc.documentElement.childNodes
demofile.Write("<" & x.nodename & ">")
'demofile.WriteLine(x.text)
for each y in x.childNodes
demofile.Write("<" & y.nodename & ">")
'demofile.WriteLine(y.text)
strItem = Split(y.text, " ")
For j = 0 To UBound(strItem)
'MsgBox(strItem(j))
demofile.Write(strItem(j) & " ")
Next
demofile.WriteLine("</" & y.nodename & ">")
next
demofile.WriteLine("</" & x.nodename & ">")
next
demofile.WriteLine("</" & xmlDoc.documentElement.nodename & ">")
'set fso = nothing
'set xmlDoc = nothing
demofile.close
next
When I am using the DOM to read elements of XML files and doing some string manipulation to get of white spaces.
It runs fine with single file but when I try to run on the entire files in a folder, it tells me that it doesn't recognize the xmlDoc object(on xmlDoc.documentElement.nodename and ones there after. then why not two above that line)
I am not sure if this VBS problme or DOM problem.
I am showing you code for one file and entire files.
I am just using vbs to render the entire folder.
I look an can't figure out what is wrong.
Thank you.
Code for single xml file:
' VB Script Document
Set fso = CreateObject("Scripting.FileSystemObject")
'dirpath = InputBox("Path to Directory :")
''set folder=fso.Getfolder(dirpath)
'set files=folder.Files
filename = "CB-000001.xml"
'for each file in files
Set demofile = fso.CreateTextFile("C:\q\xml\dom\cbiac_test.xml")
demofile.WriteLine("<?xml version='1.0' encoding='ISO-8859-1'?>")
set xmlDoc = CreateObject("Microsoft.XMLDOM")
xmlDoc.async="false"
xmlDoc.load(filename)
demofile.WriteLine("<" & xmlDoc.documentElement.nodename & ">")
for each x in xmlDoc.documentElement.childNodes
demofile.Write("<" & x.nodename & ">")
'demofile.WriteLine(x.text)
for each y in x.childNodes
demofile.Write("<" & y.nodename & ">")
'demofile.WriteLine(y.text)
strItem = Split(y.text, " ")
For j = 0 To UBound(strItem)
'MsgBox(strItem(j))
demofile.Write(strItem(j) & " ")
Next
demofile.WriteLine("</" & y.nodename & ">")
next
demofile.WriteLine("</" & x.nodename & ">")
next
demofile.WriteLine("</" & xmlDoc.documentElement.nodename & ">")
'set fso = nothing
'set xmlDoc = nothing
'demofile.close
'next
*********************************
code for the entire files:
' VB Script Document
dim xmlDoc, fso, demofile, docName
Set fso = CreateObject("Scripting.FileSystemObject")
Set xmlDoc = CreateObject("Microsoft.XMLDOM")
dirpath = InputBox("Path to Directory :")
set folder=fso.Getfolder(dirpath)
set files=folder.Files
for each file in files
Set demofile = fso.CreateTextFile("C:\q\xml\dom\cbiac\" & file.name)
demofile.WriteLine("<?xml version='1.0' encoding='ISO-8859-1'?>")
xmlDoc.async="false"
xmlDoc.load(file.name)
demofile.WriteLine("<" & xmlDoc.documentElement.nodename & ">") <<==== here ..telling object required:"documentElement
for each x in xmlDoc.documentElement.childNodes
demofile.Write("<" & x.nodename & ">")
'demofile.WriteLine(x.text)
for each y in x.childNodes
demofile.Write("<" & y.nodename & ">")
'demofile.WriteLine(y.text)
strItem = Split(y.text, " ")
For j = 0 To UBound(strItem)
'MsgBox(strItem(j))
demofile.Write(strItem(j) & " ")
Next
demofile.WriteLine("</" & y.nodename & ">")
next
demofile.WriteLine("</" & x.nodename & ">")
next
demofile.WriteLine("</" & xmlDoc.documentElement.nodename & ">")
'set fso = nothing
'set xmlDoc = nothing
demofile.close
next