Results 1 to 11 of 11

Thread: XML Completed, how do I parse it? - Re-opened!!!! :(

  1. #1

    Thread Starter
    Fanatic Member VisionIT's Avatar
    Join Date
    Nov 2002
    Location
    Workin'...
    Posts
    718

    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.

  2. #2
    Frenzied Member Jmacp's Avatar
    Join Date
    Jul 2003
    Location
    UK
    Posts
    1,959
    DOM, its quite a big subject but you could do something like,

    VB Code:
    1. Private Sub Command1_Click()
    2. Dim i As Integer
    3. Dim xml As New DOMDocument
    4. Dim root As IXMLDOMElement, det As IXMLDOMElement
    5. Dim strnode As IXMLDOMNodeList
    6. xml.Load "www.yourserver.com\file.xml"
    7. Set root = xml.documentElement
    8. Set strnode = root.selectNodes("//entry")
    9. For i = 0 To strnode.length - 1
    10. For Each det In strnode.Item(i).childNodes
    11. MsgBox det.Text
    12. Next det
    13. Next i
    14. End Sub

  3. #3

    Thread Starter
    Fanatic Member VisionIT's Avatar
    Join Date
    Nov 2002
    Location
    Workin'...
    Posts
    718
    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.

  4. #4
    Frenzied Member Jmacp's Avatar
    Join Date
    Jul 2003
    Location
    UK
    Posts
    1,959
    No prob.

    Might even want to put this in the code section, or it would be a good entry in PSC.

  5. #5

    Thread Starter
    Fanatic Member VisionIT's Avatar
    Join Date
    Nov 2002
    Location
    Workin'...
    Posts
    718
    VB Code:
    1. Public Sub Command2_Click()
    2. Dim xDoc As MSXML.DOMDocument
    3. Set xDoc = New MSXML.DOMDocument
    4. xDoc.validateOnParse = False
    5. xDoc.async = False
    6. If xDoc.Load("OOPS -- Can't see this!") Then
    7.    ' The document loaded successfully.
    8.    ' Now do something intersting.
    9.    DisplayNode xDoc.childNodes, 0
    10. Else
    11.    ' The document failed to load.
    12.    ' See the previous listing for error information.
    13. End If
    14. End Sub
    15.  
    16. Public Sub DisplayNode(ByRef Nodes As MSXML.IXMLDOMNodeList, _
    17.    ByVal Indent As Integer)
    18.    Dim tickets(6, 6) As String
    19.    Dim i As Integer
    20.      
    21.    Dim xNode As MSXML.IXMLDOMNode
    22.    Indent = Indent + 2
    23.  
    24.    For Each xNode In Nodes
    25.    i = 0
    26.       If xNode.nodeType = NODE_TEXT Then
    27. '         Debug.Print Space$(Indent) & xNode.parentNode.nodeName & _
    28.             ":" & xNode.nodeValue
    29.             'MsgBox xNode.nodeValue
    30.             tickets(i, i) = xNode.nodeValue
    31.             Debug.Print tickets(i, i)
    32.             End If
    33.  
    34.       If xNode.hasChildNodes Then
    35.          DisplayNode xNode.childNodes, Indent
    36.       End If
    37.      
    38.     Next xNode
    39. 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

  6. #6
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687
    Try this:
    VB Code:
    1. Dim tickets() as string
    2. 'Once you know how big you need it...
    3. ReDim tickets(6, x)

    TG
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  7. #7

    Thread Starter
    Fanatic Member VisionIT's Avatar
    Join Date
    Nov 2002
    Location
    Workin'...
    Posts
    718
    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!

  8. #8
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687
    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  9. #9

    Thread Starter
    Fanatic Member VisionIT's Avatar
    Join Date
    Nov 2002
    Location
    Workin'...
    Posts
    718
    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:
    1. Public Sub Command2_Click()
    2. Dim xDoc As MSXML.DOMDocument
    3. Set xDoc = New MSXML.DOMDocument
    4. xDoc.validateOnParse = False
    5. xDoc.async = False
    6. If xDoc.Load("OOPS -- Can't see this!") Then
    7.    ' The document loaded successfully.
    8.    ' Now do something intersting.
    9.    DisplayNode xDoc.childNodes, 0
    10. Else
    11.    ' The document failed to load.
    12.    ' See the previous listing for error information.
    13. End If
    14. End Sub
    15.  
    16. Public Sub DisplayNode(ByRef Nodes As MSXML.IXMLDOMNodeList, _
    17.    ByVal Indent As Integer)
    18.    Dim tickets(6, 6) As String
    19.    Dim i As Integer
    20.      
    21.    Dim xNode As MSXML.IXMLDOMNode
    22.    Indent = Indent + 2
    23.  
    24.    For Each xNode In Nodes
    25.    i = 0
    26.       If xNode.nodeType = NODE_TEXT Then
    27. '         Debug.Print Space$(Indent) & xNode.parentNode.nodeName & _
    28.             ":" & xNode.nodeValue
    29.             'MsgBox xNode.nodeValue
    30.             tickets(i, i) = xNode.nodeValue
    31.             Debug.Print tickets(i, i)
    32.             End If
    33.  
    34.       If xNode.hasChildNodes Then
    35.          DisplayNode xNode.childNodes, Indent
    36.       End If
    37.      
    38.     Next xNode
    39. 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?

  10. #10

    Thread Starter
    Fanatic Member VisionIT's Avatar
    Join Date
    Nov 2002
    Location
    Workin'...
    Posts
    718
    Anyone?

  11. #11
    Frenzied Member agmorgan's Avatar
    Join Date
    Dec 2000
    Location
    Lurking
    Posts
    1,383
    Whats wrong with what techgnome said?
    Merging your two sets of code I get
    VB Code:
    1. Public Sub Command2_Click()
    2. Dim xDoc As MSXML.DOMDocument
    3. Set xDoc = New MSXML.DOMDocument
    4. xDoc.validateOnParse = False
    5. xDoc.async = False
    6. If xDoc.Load("OOPS -- Can't see this!") Then
    7.    ' The document loaded successfully.
    8.    ' Now do something intersting.
    9.    DisplayNode xDoc.childNodes, 0
    10. Else
    11.    ' The document failed to load.
    12.    ' See the previous listing for error information.
    13. End If
    14. End Sub
    15.  
    16. Public Sub DisplayNode(ByRef Nodes As MSXML.IXMLDOMNodeList, _
    17.    ByVal Indent As Integer)
    18. '   Dim tickets(6, 6) As String
    19.    Dim tickets() As String
    20.    Dim i As Integer
    21.          Dim xNode As MSXML.IXMLDOMNode
    22.    Indent = Indent + 2
    23.  
    24.    For Each xNode In Nodes
    25.    i = 0
    26.    ReDim tickets(6, 0)
    27.       If xNode.nodeType = NODE_TEXT Then
    28. '         Debug.Print Space$(Indent) & xNode.parentNode.nodeName & _
    29.             ":" & xNode.nodeValue
    30.             'MsgBox xNode.nodeValue
    31.             i = i + 1
    32.             ReDim Preserve tickets(6, i)
    33. '            tickets(i, i) = xNode.nodeValue
    34. '            Debug.Print tickets(i, i)
    35.             tickets(6, i) = xNode.nodeValue
    36.             Debug.Print tickets(6, i)
    37.             End If
    38.  
    39.       If xNode.hasChildNodes Then
    40.          DisplayNode xNode.childNodes, Indent
    41.       End If
    42.           Next xNode
    43.          
    44.  
    45. 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
  •  



Click Here to Expand Forum to Full Width