-
xml to text vb6 code
Hi there,
I am a new member over here! I don't know if I am posting on the right place!
First I would like to ask the premission to use the xml to text vb code in my porject! My question is about the code: Are there any references needed to run the code and how is the function called?
Thanks in advance
Jaton
-
Split into its own thread and moved to VB Classic
I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
Please use [Code]your code goes in here[/Code] tags when posting code.
Before posting your question, did you look here?
Got a question on Linux? Visit our Linux sister site.
Modifications Required For VB6 Apps To Work On Vista
-
Xml to text
Hi there,
Thanks for the help!
Again I would like to ask the premission to use the xml to text vb code in my porject! My question is about the code: Are there any references needed to run the code and how is the function called?
The code is as follows:
Maybe the link can be helpful: http://www.devx.com/getHelpOn/10MinuteSolution/20356
Code:
Listing 3.
The XML2Text() function will take an XML document and appropriate query strings, and convert them into a delimited list. Note that you can pass either a node or an entire DOM as the first parameter, so long as your query strings reflect this.
Function XML2Text(xmlNode As Variant, Optional recordQuery As String = "*", _
Optional propertyQuery As String = "*", Optional filename As String = "", _
Optional Delimiter As String = ",") As String
Dim buffer As String
Dim recNodeList As IXMLDOMNodeList
Dim propNodeList As IXMLDOMNodeList
Dim srcNode As IXMLDOMElement
Dim recNode As IXMLDOMElement
Dim propNode As IXMLDOMElement
Dim fs As FileSystemObject
Dim ts As TextStream
' If the object passed is an xml document then
' return its document element,
If TypeName(xmlNode) = "DOMDocument" Then
Set srcNode = xmlNode.documentElement
Else
' Otherwise if its an element or node,
' set it to a node element
If TypeName(xmlNode) = "IXMLDOMNode" Or TypeName(xmlNode) = "IXMLDOMElement" Then
Set srcNode = xmlNode
Else
' Otherwise return an empty string
' and terminate
XML2Text = ""
Exit Function
End If
End If
' This performs the actual query against the XML
' object to create the record nodelist
Set recNodeList = xmlDoc.selectNodes(recordQuery)
If recNodeList.length = 0 Then
' If no nodes are produced then return an
' empty string
XML2Text = ""
Exit Function
Else
' Otherwise, set the first record
Set recNode = recNodeList(0)
' iterate through the properties
For Each propNode In recNode.selectNodes(propertyQuery)
' add the name and a delimiter
buffer = buffer + propNode.nodeName + Delimiter
Next
' remove the last delimiter and append a carriage return
buffer = Left(buffer, Len(buffer) - Len(Delimiter)) + vbCrLf
' iterate through each record
For Each recNode In recNodeList
' iterate through each property
For Each propNode In recNode.selectNodes(propertyQuery)
' Add the property value to the buffer
buffer = buffer + propNode.Text + Delimiter
Next
' remove the last delimiter and append a CR
buffer = Left(buffer, Len(buffer) - Len(Delimiter)) + vbCrLf
Next
End If
' remove the last carriage return
buffer = Left(buffer, Len(buffer) - Len(vbCrLf))
' assign the buffer to the text name
' Open the Common Value Separated (CVS) text file
Set fs = CreateObject("Scripting.FileSystemObject")
Set ts = fs.OpenTextFile(textFilePath, ForWriting, True, TristateUseDefault)
ts.Write buffer
ts.Close
XML2Text = buffer
End Function
Willing to receive from you soon
Thanks in advance
Jaton
-
If you don't have any references set, then I'm sure you are getting errors, so yes you do need a reference to Microsoft XML, v6.0
I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
Please use [Code]your code goes in here[/Code] tags when posting code.
Before posting your question, did you look here?
Got a question on Linux? Visit our Linux sister site.
Modifications Required For VB6 Apps To Work On Vista
-
XML to text
Hi Hack 
I tried to add the reference Microsoft XML Version 6 and still the same message appears when I run the program (Object is Required).
What would the solution be?
Thanks so much
Jaton
-
What line of code is causing the error?
I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
Please use [Code]your code goes in here[/Code] tags when posting code.
Before posting your question, did you look here?
Got a question on Linux? Visit our Linux sister site.
Modifications Required For VB6 Apps To Work On Vista
-
xml to text in vb 6
Hi Hack 
Please have a look at my code:
After compiling this line: "Set testDoc = XML2Text("c:\expidition1.xml", "//employe[dept='Accounting']", "name|dateOfBirth", "employeesSub.txt ", vbTab) was highlighted. A prompt message appeared on the screen saying Object Required.
Note that I have the xml file saved on the same directery with the code.
Code:
Private Sub Command1_Click()
Dim testDoc
'Set testDoc = XML2Text(EmployeeXML, "//employee[dept='Accounting']", "name|dateOfBirth", employeesSub.txt, vbTab)
Set testDoc = XML2Text("c:\expidition1.xml", "//employee[dept='Accounting']", "name|dateOfBirth", "employeesSub.txt ", vbTab)
testDoc.save "c:/employeesSub.txt"
End Sub
Public Function XML2Text(xmlNode As Variant, Optional recordQuery As String = "*", _
Optional propertyQuery As String = "*", Optional filename As String = "", _
Optional Delimiter As String = ",") As String
Dim buffer As String
Dim recNodeList As IXMLDOMNodeList
Dim propNodeList As IXMLDOMNodeList
Dim srcNode As IXMLDOMElement
Dim recNode As IXMLDOMElement
Dim propNode As IXMLDOMElement
Dim fs As FileSystemObject
Dim ts As TextStream
Dim testDoc As DOMDocument
Set testDoc = CreateObject("Microsoft.XMLDOM")
Set usersDoc.documentElement = usersDoc.createElement(collectionName)
' If the object passed is an xml document then
' return its document element,
If TypeName(xmlNode) = "DOMDocument" Then
Set srcNode = xmlNode.documentElement
Else
' Otherwise if its an element or node,
' set it to a node element
If TypeName(xmlNode) = "IXMLDOMNode" Or TypeName(xmlNode) = "IXMLDOMElement" Then
Set srcNode = xmlNode
Else
' Otherwise return an empty string
' and terminate
XML2Text = ""
Exit Function
End If
End If
' This performs the actual query against the XML
' object to create the record nodelist
Set recNodeList = xmlDoc.selectNodes(recordQuery)
If recNodeList.length = 0 Then
' If no nodes are produced then return an
' empty string
XML2Text = ""
Exit Function
Else
' Otherwise, set the first record
Set recNode = recNodeList(0)
' iterate through the properties
For Each propNode In recNode.selectNodes(propertyQuery)
' add the name and a delimiter
buffer = buffer + propNode.nodeName + Delimiter
Next
' remove the last delimiter and append a carriage return
buffer = Left(buffer, Len(buffer) - Len(Delimiter)) + vbCrLf
' iterate through each record
For Each recNode In recNodeList
' iterate through each property
For Each propNode In recNode.selectNodes(propertyQuery)
' Add the property value to the buffer
buffer = buffer + propNode.Text + Delimiter
Next
' remove the last delimiter and append a CR
buffer = Left(buffer, Len(buffer) - Len(Delimiter)) + vbCrLf
Next
End If
' remove the last carriage return
buffer = Left(buffer, Len(buffer) - Len(vbCrLf))
' assign the buffer to the text name
' Open the Common Value Separated (CVS) text file
Set fs = CreateObject("Scripting.FileSystemObject")
Set ts = fs.OpenTextFile(textFilePath, ForWriting, True, TristateUseDefault)
ts.Write buffer
' ts.Close
Set XML2Text = buffer
End Function
Thanks in advance!

Jaton
-
xml to text in vb6
Hi Guys,
I am still waiting for an answer of my last post!
Can anybody help? It is urgent!
Similar Threads
-
By Kostas Zotos in forum XML
Replies: 2
Last Post: 10-22-2008, 10:37 AM
-
By echozero in forum VB Classic
Replies: 4
Last Post: 11-13-2007, 10:00 PM
-
Replies: 5
Last Post: 01-10-2003, 08:39 PM
-
By Daniel Pratt in forum .NET
Replies: 27
Last Post: 09-16-2002, 11:36 AM
-
Replies: 90
Last Post: 04-17-2001, 12:45 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks