|
-
Aug 5th, 2004, 05:21 AM
#1
Thread Starter
Fanatic Member
XML Completed, how do I parse it? - Re-opened!!!! :(
<?xml version="1.0" ?>
- <entries>
- <entry>
<id>1</id>
<mask>AHW-93664-489</mask>
<subject>Tester 1</subject>
<assigned>3</assigned>
<timedue>2004-07-05 00:00:00</timedue>
<status>resolved</status>
</entry>
- <entry>
<id>1</id>
<mask>HKO-50919-712</mask>
<subject>Tester 2</subject>
<assigned>0</assigned>
<timedue>2004-08-09 15:11:58</timedue>
<status>reopened</status>
</entry>
</entries>
Above is the result of a PHP file which creates XML data from a MySQL table.
How do I go about getting that data from the server into an app?
I gather i'de need an array of some sort, but i've been looking at this code for so long, i'm completely blind to what to do next 
Please help.
Ta
Last edited by VisionIT; Aug 5th, 2004 at 08:51 AM.
-
Aug 5th, 2004, 06:20 AM
#2
DOM, its quite a big subject but you could do something like,
VB Code:
Private Sub Command1_Click()
Dim i As Integer
Dim xml As New DOMDocument
Dim root As IXMLDOMElement, det As IXMLDOMElement
Dim strnode As IXMLDOMNodeList
xml.Load "www.yourserver.com\file.xml"
Set root = xml.documentElement
Set strnode = root.selectNodes("//entry")
For i = 0 To strnode.length - 1
For Each det In strnode.Item(i).childNodes
MsgBox det.Text
Next det
Next i
End Sub
Last edited by Jmacp; Aug 5th, 2004 at 06:24 AM.
-
Aug 5th, 2004, 06:56 AM
#3
Thread Starter
Fanatic Member
I've coded a bit of DOM, and to my surprise it's working perfectly! 
Thank you for your help m8, it's very much appreciated.
-
Aug 5th, 2004, 07:07 AM
#4
No prob.
Might even want to put this in the code section, or it would be a good entry in PSC.
-
Aug 5th, 2004, 08:50 AM
#5
Thread Starter
Fanatic Member
VB Code:
Public Sub Command2_Click()
Dim xDoc As MSXML.DOMDocument
Set xDoc = New MSXML.DOMDocument
xDoc.validateOnParse = False
xDoc.async = False
If xDoc.Load("OOPS -- Can't see this!") Then
' The document loaded successfully.
' Now do something intersting.
DisplayNode xDoc.childNodes, 0
Else
' The document failed to load.
' See the previous listing for error information.
End If
End Sub
Public Sub DisplayNode(ByRef Nodes As MSXML.IXMLDOMNodeList, _
ByVal Indent As Integer)
Dim tickets(6, 6) As String
Dim i As Integer
Dim xNode As MSXML.IXMLDOMNode
Indent = Indent + 2
For Each xNode In Nodes
i = 0
If xNode.nodeType = NODE_TEXT Then
' Debug.Print Space$(Indent) & xNode.parentNode.nodeName & _
":" & xNode.nodeValue
'MsgBox xNode.nodeValue
tickets(i, i) = xNode.nodeValue
Debug.Print tickets(i, i)
End If
If xNode.hasChildNodes Then
DisplayNode xNode.childNodes, Indent
End If
Next xNode
End Sub
Thats the code i'm using to get the XML data, and it shows every section of data perfectly in the immediate debug window... but it plain refuses to put each entry in it's own variable!!!!! Again, help :P
Does anyone know what I can add the that code to put each section of the XML into an array?
If the array has these sections:
1. ID
2. Mask
3. Assigned
4. timedue
5. Resolved
6. Subject
So the array needs 6 sections. It's been nearly 3 years since I coded properly so i'm very rusty.. hence all the problems. But I remember you can use something like:
dim tickets(6,10) as string
Where six is the amount of options in each part of the XML, but the other figure would be anything, depending on how many fields the PHP file brings from the SQL database. So i'de need:
dim tickets(6,unlimited) as string
but obviously that won't work
Hope this makes some sort of sense 
Thanx again
-
Aug 5th, 2004, 09:08 AM
#6
Try this:
VB Code:
Dim tickets() as string
'Once you know how big you need it...
ReDim tickets(6, x)
TG
-
Aug 5th, 2004, 09:14 AM
#7
Thread Starter
Fanatic Member
Thats the problem m8! I don't know how big it is until it connects.
Here's the complete setup.
There is a file on the server called getdata.php which connects to the MySQL server and adds all rows in a specific table to an XML form. This XML is displayed in the PHP file automatically.
The client application connects to this PHP file and and the above code reads and formats the XML data.
Only problem being, there could be 3 lines or 300 lines in the MySQL document, which is why i'm struggling with the array code. It has to have 6 sections for obvious reasons, but the other figure is dynamic.
I'll have a look at that code and see if it works. Any other idea's based on the above... please let me know!
-
Aug 5th, 2004, 09:34 AM
#8
OK, so try this:
Dim tickets() as string
Set counter = 0
ReDim Tickets(6,0)
Open file
Read line
Counter = Counter + 1
ReDim Preserve Tickets(6, Counter)
Stuff data into Tickets
Keep looping until EOF
Done!
TG
-
Aug 5th, 2004, 10:02 AM
#9
Thread Starter
Fanatic Member
Not done 
I can't believe it's this damn hard... surely other people have used XML in VB!
I'm lost with this now!
VB Code:
Public Sub Command2_Click()
Dim xDoc As MSXML.DOMDocument
Set xDoc = New MSXML.DOMDocument
xDoc.validateOnParse = False
xDoc.async = False
If xDoc.Load("OOPS -- Can't see this!") Then
' The document loaded successfully.
' Now do something intersting.
DisplayNode xDoc.childNodes, 0
Else
' The document failed to load.
' See the previous listing for error information.
End If
End Sub
Public Sub DisplayNode(ByRef Nodes As MSXML.IXMLDOMNodeList, _
ByVal Indent As Integer)
Dim tickets(6, 6) As String
Dim i As Integer
Dim xNode As MSXML.IXMLDOMNode
Indent = Indent + 2
For Each xNode In Nodes
i = 0
If xNode.nodeType = NODE_TEXT Then
' Debug.Print Space$(Indent) & xNode.parentNode.nodeName & _
":" & xNode.nodeValue
'MsgBox xNode.nodeValue
tickets(i, i) = xNode.nodeValue
Debug.Print tickets(i, i)
End If
If xNode.hasChildNodes Then
DisplayNode xNode.childNodes, Indent
End If
Next xNode
End Sub
That above code prints everything into the debug window perfectly... line by line. Is there anyone that can put a line(s) in that script to make each line of data go into it's own variable?
-
Aug 5th, 2004, 10:37 AM
#10
Thread Starter
Fanatic Member
-
Aug 6th, 2004, 06:16 AM
#11
Frenzied Member
Whats wrong with what techgnome said?
Merging your two sets of code I get
VB Code:
Public Sub Command2_Click()
Dim xDoc As MSXML.DOMDocument
Set xDoc = New MSXML.DOMDocument
xDoc.validateOnParse = False
xDoc.async = False
If xDoc.Load("OOPS -- Can't see this!") Then
' The document loaded successfully.
' Now do something intersting.
DisplayNode xDoc.childNodes, 0
Else
' The document failed to load.
' See the previous listing for error information.
End If
End Sub
Public Sub DisplayNode(ByRef Nodes As MSXML.IXMLDOMNodeList, _
ByVal Indent As Integer)
' Dim tickets(6, 6) As String
Dim tickets() As String
Dim i As Integer
Dim xNode As MSXML.IXMLDOMNode
Indent = Indent + 2
For Each xNode In Nodes
i = 0
ReDim tickets(6, 0)
If xNode.nodeType = NODE_TEXT Then
' Debug.Print Space$(Indent) & xNode.parentNode.nodeName & _
":" & xNode.nodeValue
'MsgBox xNode.nodeValue
i = i + 1
ReDim Preserve tickets(6, i)
' tickets(i, i) = xNode.nodeValue
' Debug.Print tickets(i, i)
tickets(6, i) = xNode.nodeValue
Debug.Print tickets(6, i)
End If
If xNode.hasChildNodes Then
DisplayNode xNode.childNodes, Indent
End If
Next xNode
End Sub
Does that work?
Or do you need to resize both dimensions of the array?
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
|
Click Here to Expand Forum to Full Width
|