Login | |
|
 |
RE: XML to CSV in VBScript - 9/12/2005 8:14:16 PM
|
|
 |
|
| |
Zifter
Posts: 318
Score: 0
Joined: 1/5/2005
From: Belgium
Status: offline
|
Each time you use the Wscript.Echo command, the text is shown on a new line. If you want to echo it all on one line, you'll first have to add all your output to a variable and then echo that value of that variable. Example 1: WScript.Echo "This" WScript.Echo " is" WScript.Echo " a" WScript.Echo " test" Output: This is a test Example 2: strMyText = "This" strMyText = strMyText & " is" strMyText = strMyText & " a" strMyText = strMyText & " test" WScript.Echo strMyText Output: This is a test Note: WScript.Echo isn't a command to write text to a file (it can, if you pipe your scripts output to a file), but if you want to write to a file, you'll need to use the FileSystemObject to open or create a file and then use the Write or WriteLine methods to put your text into this file. Check the documentation to see how to use the FileSystemObject or do a search on this forum (lots of topics)
|
|
| |
|
|
|
 |
RE: XML to CSV in VBScript - 9/12/2005 10:23:01 PM
|
|
 |
|
| |
Zifter
Posts: 318
Score: 0
Joined: 1/5/2005
From: Belgium
Status: offline
|
I answered this question in the update (edit) of post number40 (on page 2) (saw this one cumming )
|
|
| |
|
|
|
 |
RE: XML to CSV in VBScript - 9/13/2005 11:51:44 PM
|
|
 |
|
| |
Zifter
Posts: 318
Score: 0
Joined: 1/5/2005
From: Belgium
Status: offline
|
I covered this question also in the edit of post 40 on page 2. Test the script I posted between the 'edit tags' and try to understand what I'm doing there. If it's not clear what happens in my example I will be glad to explain. <edit> I reread your last post, and now I'm confused. What is wrong with the ChildNode.NodeName and ChildNode.text ? The ChildNode.NodeName is the name of the tag like <name> and <capital> The ChildNode.Text is what value this tag has, like "Florida" and "Tallahassee" If you want the "<"' and ">" around the NodeName, you could just concatenate them like WScript.Echo "<" & ChildNode.NodeName & ">" </edit>
< Message edited by Zifter -- 9/13/2005 11:58:31 PM >
|
|
| |
|
|
|
 |
RE: XML to CSV in VBScript - 9/18/2005 8:02:59 PM
|
|
 |
|
| |
Zifter
Posts: 318
Score: 0
Joined: 1/5/2005
From: Belgium
Status: offline
|
You can try to select the node and if the returned object "Is Nothing", then it means that the node couldn't be retrieved, so you can conclude that the node doesn't exist. Check this example: Option Explicit Dim objXML Dim objNode Set objXML = CreateObject("Microsoft.XMLDOM") objXML.async = False objXML.load("c:\test\test.xml") fnCheckNode "Year" fnCheckNode "Genre" Set objXML = Nothing '------------------------------------------------------------------------------- Function fnCheckNode(strNodeName) Set objNode = objXML.documentElement.selectSingleNode(strNodeName) If objNode Is Nothing Then WScript.Echo "Node " & strNodeName & " doesn't exist" Else WScript.Echo "Node " & objNode.nodeName & " has a value of " & objNode.Text Set objNode = Nothing End If End Function For this example the XML file "test.xml" contains the XML you provided in your last post. Note that the nodenames are case sensitive! HTH
< Message edited by Zifter -- 9/18/2005 8:04:41 PM >
|
|
| |
|
|
|
 |
RE: XML to CSV in VBScript - 9/18/2005 8:34:35 PM
|
|
 |
|
| |
Zifter
Posts: 318
Score: 0
Joined: 1/5/2005
From: Belgium
Status: offline
|
In all the XML examples I posted I used the object "Microsoft.XMLDOM" I just read somewhere on the internet (lost the URL), that this is an old object and you better use the most recent one (they folow the W3C standards better) So change the statement Set objXML = CreateObject("Microsoft.XMLDOM") into Set objXML = CreateObject("MSXML2.DOMDocument.3.0") or Set objXML = CreateObject("MSXML2.DOMDocument.4.0") or Set objXML = CreateObject("MSXML2.DOMDocument.5.0") ... take the highest version you have installed. HTH
|
|
| |
|
|
|
 |
RE: XML to CSV in VBScript - 9/18/2005 9:38:16 PM
|
|
 |
|
| |
Zifter
Posts: 318
Score: 0
Joined: 1/5/2005
From: Belgium
Status: offline
|
I only know that the "MSXML2.DOMDocument.x.x" objects follow the W3C standards better then the "Microsoft.XMLDOM" object. I don't know (and couldn't find) the differences between all the versions of the "MSXML2.DOMDocument.x.x" objects...
|
|
| |
|
|
|
 |
RE: XML to CSV in VBScript - 9/19/2005 1:17:07 AM
|
|
 |
|
| |
Zifter
Posts: 318
Score: 0
Joined: 1/5/2005
From: Belgium
Status: offline
|
If I understand what you are trying to do, then the selectSingleNode method is the one you need. If it's not working like you expect it, then it's probably because your XPath is not correct. The parameter you give with the selectSingleNode method needs to be an XSL Patterns query OR an XPath expression if you specify the green statement before the selectSingleNode method objXML.setProperty("SelectionLanguage", "XPath") objNode = objXML.selectSingleNode("//books/ref")
|
|
| |
|
|
|
|
|