Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


RE: XML to CSV in VBScript

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,25624
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> RE: XML to CSV in VBScript
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: <<   < prev  1 [2] 3 4 5   next >   >>
Login
Message << Older Topic   Newer Topic >>
 RE: XML to CSV in VBScript - 9/8/2005 1:17:13 AM   
  ebgreen


Posts: 4595
Score: 29
Joined: 7/12/2005
Status: offline
If you are going to be writing your own parser, I would highly recommend looking at Regular Expressions and Dictionaries. If I were writing a parser, I would use regular expressions to build a dictionary representation of the xml file. The dictionary could hold dictionaries to an arbitrary level of recursion that would only be limited by your machine's memory.

(in reply to reloader)
 
 
Post #: 21
 
 RE: XML to CSV in VBScript - 9/8/2005 1:29:07 AM   
  reloader

 

Posts: 72
Score: 0
Joined: 9/5/2005
Status: offline
Thanks for your advice ebgreen. I have a look at reg. expressions.

(in reply to ebgreen)
 
 
Post #: 22
 
 RE: XML to CSV in VBScript - 9/8/2005 8:01:55 AM   
  mconnelly

 

Posts: 3
Score: 0
Joined: 9/7/2005
Status: offline
Just remove everything after as in dim or dimension statements unless using explicit option in vbscript
otherwise change to variant or object as needed.

If you are running on a windows system xml parser is a default install on WinXP and win2000.
C:\WINDOWS\system32\msxml4.dll
or
C:\WINDOWS\system32\msxml3.dll

It is also required and installed  by IE5 and 6.0

What sort of security are you running that allows vbscript access and not an xml parser?
vbscript access is way more insecure and is more likely to be turned off.

By the way the xsl code I gave, you requires XQuery and XPath to handle the XSLT transform.
so you will have to code those languages from scratch as well.

So here is the W3C RFC specs for the languages
Document Object Model (DOM) Level 3 XPath Specification

http://www.w3.org/TR/DOM-Level-3-XPath/

Here is James Clark's  Expat XML parser library in C.
It is only about 30,000 lines of code
http://sourceforge.net/projects/expat






(in reply to ebgreen)
 
 
Post #: 23
 
 RE: XML to CSV in VBScript - 9/8/2005 5:42:31 PM   
  reloader

 

Posts: 72
Score: 0
Joined: 9/5/2005
Status: offline
Hi mconnelly,

Exactly, I searched for these dll's, and nothing was found.:(

I don't know how can they setup WSH on the machine, but I cannot install anything else, and the administrators don't allow the installing.
I'm trying to do something else, but I suppose, there will be no way to make this task.

Thanks for the links, I have a look at these ones.

(in reply to mconnelly)
 
 
Post #: 24
 
 RE: XML to CSV in VBScript - 9/8/2005 7:25:06 PM   
  Zifter


Posts: 318
Score: 0
Joined: 1/5/2005
From: Belgium
Status: offline
Maybe you can first try if the script can create the XMLDOM object?

With the following code you could test this:


Option Explicit

Dim objXML

Set objXML = CreateObject("Microsoft.XMLDOM")

If objXML Is Nothing Then
WScript.Echo "Failed to create object"
Else
WScript.Echo "Successfully created the object"
End If

Set objXML = Nothing


Note that if the script can't create the object, you won't get the message "Failed to create object", you will get an error in stead "ActiveX component can't create object: 'Microsoft.XMLDOM'"
If you want to script to return the failed message, you'll have to put the script between the statements "On Error Resume Next" and "On Error Goto 0".


HTH

(in reply to reloader)
 
 
Post #: 25
 
 RE: XML to CSV in VBScript - 9/8/2005 9:36:36 PM   
  reloader

 

Posts: 72
Score: 0
Joined: 9/5/2005
Status: offline
Zifter, it's working!

(in reply to Zifter)
 
 
Post #: 26
 
 RE: XML to CSV in VBScript - 9/8/2005 10:08:18 PM   
  Zifter


Posts: 318
Score: 0
Joined: 1/5/2005
From: Belgium
Status: offline
Congratulations

(in reply to reloader)
 
 
Post #: 27
 
 RE: XML to CSV in VBScript - 9/9/2005 12:18:51 AM   
  reloader

 

Posts: 72
Score: 0
Joined: 9/5/2005
Status: offline
Thanks!

At the moment I'm trying to create a varibale what contains some variables.

In example:

Dim ch(3)


ch(1)=("a")
ch(2)=("b")
ch(3)=("c")
 

dh= ch(1)+ch(2)+ch(3)

My problem is, when the script doesn't know how many ch will be.

In example:

Dim ch(10)

Do until x=2 'X will be 2 is a random task
i=i+1
ch(i)=x
Loop

dh=????? How can I append the ch's in a variable if I don't know how much will be?


(in reply to Zifter)
 
 
Post #: 28
 
 RE: XML to CSV in VBScript - 9/9/2005 12:28:27 AM   
  Zifter


Posts: 318
Score: 0
Joined: 1/5/2005
From: Belgium
Status: offline
First of all, arrays in VbScript are zero based. Which means that the first element of the array has index zero.
If you define a array like this ch(3), you actually have four elements in this array (from index 0 till index 3)
With the UBound() function, you can retrieve the upper bound of an array.

One other small remark: it's better to use the ampersand (&) to concatenate strings and use the plus sign (+) to add arithmetic values.

Maybe an example explains it better:


Dim ch(3)

ch(0) = "a"
ch(1) = "b"
ch(2) = "c"
ch(3) = "d"

For i = 0 To UBound(ch)
   dh = dh & ch(i)
Next
WScript.Echo dh



(in reply to reloader)
 
 
Post #: 29
 
 RE: XML to CSV in VBScript - 9/9/2005 12:38:54 AM   
  reloader

 

Posts: 72
Score: 0
Joined: 9/5/2005
Status: offline
Great thanks Zifter,

It"s working! And what can I do, that I want to store in mirror? So not: abcd but dcba?

(in reply to Zifter)
 
 
Post #: 30
 
 RE: XML to CSV in VBScript - 9/9/2005 12:45:01 AM   
  Zifter


Posts: 318
Score: 0
Joined: 1/5/2005
From: Belgium
Status: offline
Then you could set the "Step" in the For-Next loop to -1 (default it is 1)

Examples often explain better:


For i = UBound(ch) To 0 Step -1
  dh = dh & ch(i)
Next





(in reply to reloader)
 
 
Post #: 31
 
 RE: XML to CSV in VBScript - 9/9/2005 1:10:29 AM   
  reloader

 

Posts: 72
Score: 0
Joined: 9/5/2005
Status: offline
Yes, thank you.

I think about the backstep, but I don't know wich command can do it.

(in reply to Zifter)
 
 
Post #: 32
 
 RE: XML to CSV in VBScript - 9/9/2005 1:15:20 AM   
  Zifter


Posts: 318
Score: 0
Joined: 1/5/2005
From: Belgium
Status: offline
Well, in the pinned post (http://www.visualbasicscript.com/m_24727/tm.htm) there are some links to the WSH documentation and other very interesting pages about VbScript.
I would suggest you look into these, especially for the basic things.

And you can still post your problems and/or questions here of course!


(in reply to reloader)
 
 
Post #: 33
 
 RE: XML to CSV in VBScript - 9/11/2005 5:38:57 PM   
  reloader

 

Posts: 72
Score: 0
Joined: 9/5/2005
Status: offline
Thanks Zifter,

I began to write mconnelly's code in VBscript, but it's not working.

It said: The styleshhet is empty, or not acceptable XML format (or something similar). I don't no why, I saved the XSL document.

(in reply to Zifter)
 
 
Post #: 34
 
 RE: XML to CSV in VBScript - 9/11/2005 5:53:12 PM   
  reloader

 

Posts: 72
Score: 0
Joined: 9/5/2005
Status: offline
Does anybody know,that how can I do it in VBScript:

WriteFile "C:\Access files\xmltests\CSVtype" & Format(Now, "yyyymmddhhmmss") & ".csv", strTransform

?


(in reply to reloader)
 
 
Post #: 35
 
 RE: XML to CSV in VBScript - 9/11/2005 11:11:44 PM   
  reloader

 

Posts: 72
Score: 0
Joined: 9/5/2005
Status: offline
Is there any normal and complete documentation about VBScript??

Slowly, I'm goint to mad.
XMLDOM is a very useful thing in parsing, but how can I find out, that what can follow documentElement. ?? ChildNodes is okay but the others? As I rember in VB was an automatic list of these things, but in VBS.

(in reply to reloader)
 
 
Post #: 36
 
 RE: XML to CSV in VBScript - 9/11/2005 11:54:39 PM   
  Zifter


Posts: 318
Score: 0
Joined: 1/5/2005
From: Belgium
Status: offline
In the pinned post (where I link to in post number 33) you can find links to the VbScript documentation.
And in another post of mine (number 5) I provided a link specifically about the XMLDOM object. Just re-read this topic.

If you get an automatic list of properties and methods about an object, then that is because the editor you're using supports this. This has nothing to do with the language itself.
There are editors which have code-completion and a kind of IntelliSense and much more to help you develop your scripts.
UltraEdit or PrimalScript , just to name two. Check the net (or the google adds on this site)

(in reply to reloader)
 
 
Post #: 37
 
 RE: XML to CSV in VBScript - 9/12/2005 12:47:43 AM   
  reloader

 

Posts: 72
Score: 0
Joined: 9/5/2005
Status: offline
Thx Zifter, it's a pretty good documentation!
I found a method, but I don't know how can I solve, that the code list all of item(FL too), not just IA?

States>
  <State ref="FL" const="27">
     <name>Florida</name>
     <capital>Tallahassee</capital>
  </State>
  <State ref="IA" const="29">
     <name>Iowa</name>
     <capital>Des Moines</capital>
  </State>
</States>

Code (VBScript):
Set objXMLDoc = CreateObject("Microsoft.XMLDOM")
objXMLDoc.async = False
objXMLDoc.load("states.xml")

Set objLastChild = objXMLDoc.documentElement.lastChild
Set objAttributes = objLastChild.attributes
Set objRefAttr = objAttributes.getNamedItem("ref")
document.write(objRefAttr.nodeValue)
Output:
IA

(in reply to Zifter)
 
 
Post #: 38
 
 RE: XML to CSV in VBScript - 9/12/2005 6:10:11 PM   
  reloader

 

Posts: 72
Score: 0
Joined: 9/5/2005
Status: offline

Hi All,

Dim
getAttr, i

Set
objXMLDoc = CreateObject("Microsoft.XMLDOM")
objXMLDoc.async =
False
objXMLDoc.load(
"P:\books.xml")




Set
NodeList = objXMLDoc.getElementsByTagName("author")
numNodes = NodeList.Length

For
i = 7374 To NumNodes

Set CurrNode = NodeList.nextNode

wscript.echo(CurrNode.text)

Next





For
Each x In objXMLDoc.documentElement.ChildNodes

Set
coll = objXMLDoc.getElementsByTagName("book").item(i)
getAttr = coll.Attributes.getNamedItem(
"id").Text
wscript.echo (getAttr)
i=i+
155156

Next

I get an error messgae for the red line, that: "Object required: 'coll'", but I set it above this line. What can be the problem?

(in reply to reloader)
 
 
Post #: 39
 
 RE: XML to CSV in VBScript - 9/12/2005 7:12:17 PM   
  Zifter


Posts: 318
Score: 0
Joined: 1/5/2005
From: Belgium
Status: offline
Hope this example gets you on your way:

XML:
      Script:


Option Explicit

Dim objXMLDoc
Dim NodeList
Dim Node
Dim ChildNode

Set objXMLDoc = CreateObject("Microsoft.XMLDOM")
objXMLDoc.async = False
objXMLDoc.load("C:\test\States.xml")

Set NodeList = objXMLDoc.documentElement.SelectNodes("State")
For Each Node In NodeList
WScript.Echo "ref: " & Node.getAttribute("ref")
WScript.Echo "const: " & Node.getAttribute("const")
For Each ChildNode In Node.ChildNodes
     WScript.Echo ChildNode.NodeName & ": "  & ChildNode.Text
Next
WScript.Echo "-------------"
Next




<edit>
You don't need to know the names of the nodes or attributes to be able to list them, like in the previous example. The following example demonstrates this:


Option Explicit

Dim objXMLDoc
Dim NodeList
Dim Node
Dim ChildNode
Dim NodeAttr

Set objXMLDoc = CreateObject("Microsoft.XMLDOM")
objXMLDoc.async = False
objXMLDoc.load("C:\test\States.xml")

For Each Node In objXMLDoc.documentElement.childNodes
   For Each NodeAttr In Node.Attributes
       WScript.Echo NodeAttr.Name & ": " & NodeAttr.Value
   Next
   For Each ChildNode In Node.ChildNodes
       WScript.Echo ChildNode.NodeName & ": "  & ChildNode.Text
   Next
   WScript.Echo "-------------"
Next


</edit>

< Message edited by Zifter -- 9/12/2005 8:04:07 PM >

(in reply to reloader)
 
 
Post #: 40
 
 
Page:  <<   < prev  1 [2] 3 4 5   next >   >>
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> RE: XML to CSV in VBScript Page: <<   < prev  1 [2] 3 4 5   next >   >>
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts