Results 1 to 9 of 9

Thread: VB6 XML Parse

  1. #1

    Joined
    Dec 2011
    Posts
    151
    Userbars
    2
    Thanks
    4
    Thanked
    165/45
    DL/UL
    14/9
    Mentioned
    68 times
    Time Online
    6d 17h 26m
    Avg. Time Online
    2m

    VB6 XML Parse

    I have a VB6 (yes believe it or not it is an XP machine and requires XP, because of a com port barcode scanner). The program is using XML in VB6, I can get the code to load the XML into a richtextbox. I can load my required contents into a nodelist; but when I go to show the parsed contents, it only shows one item twice (I need it to show all items that would match Serial_No )?

    I am not really sure how to read XML properly, to determine if I am selecting the correct data in the select nodes (or requesting the correct single node information). If anyone can help I would really appreciate it.


    This is the code I came up with
    Code:
    Option Explicit
    Dim strXML As String
    
    Private Sub Command1_Click()
    On Error Resume Next
    Dim objDoc As MSXML2.DOMDocument
    Dim objNodelist As IXMLDOMNodeList
    Dim objNode As IXMLDOMNode
    Dim x As Integer
    'x = 0
        'load the XML
        Set objDoc = New DOMDocument
        objDoc.async = False
        objDoc.Load App.Path & ("\Inventory4.xml")
        
    
        
    '    See what you loaded
    '    Debug.Print objDoc.xml
        RichTextBox1.Text = objDoc.xml
            
    '    Get a nodelist with all the Inventory nodes
       Set objNodelist = objDoc.selectNodes("//Column[Name='Serial_No']/Value")
    
        'Loop through the nodelist and pull the vaules you need
        For Each objNode In objNodelist
            Text1.Text = objNode.selectSingleNode("//Column[Name='Serial_No']/Value").xml & vbCrLf & Text1.Text
        Next objNode
    
        'Cleanup
        Set objNodelist = Nothing
        Set objDoc = Nothing
    '
    End Sub
    
    Private Sub Form_Load()
        Text1.Text = ""
    End Sub
    This the XML
    Code:
    <soap:Envelope xmlns:soap="http://www.test.org/2003/05/soapenvelope"
    xmlns:xsi="http://www.test.org/2001/XMLSchemainstance"
    xmlns:xsd="http://www.test.org/2001/XMLSchema-instance">
    <soap:Body>
    <ExecuteDataSourceResponse xmlns="http://www.testaccount.com/TestSource">
    <ExecuteDataSourceResult>
    <StatusNo>0</StatusNo>
    <Error>false</Error>
    <ErrorNo>0</ErrorNo>
    <Message>Success</Message>
    <InstanceNo>227</InstanceNo>
    <DataSourceKey>1833</DataSourceKey>
    <QuarantinedForDevelopment xsi:nil="true"/>
    <LastPrimaryDeployment xsi:nil="true"/>
    <LastTestDeployment xsi:nil="true"/>
    <Version xsi:nil="true"/>
    <DataSourceName>Inventory_By_Type_Get</DataSourceName>
    <ResultSets>
    <ResultSet>
    <RowCount>2</RowCount>
    <Rows>
    <Row>
    <Columns>
    <Column>
    <Value>CF000007</Value>
    <Name>Serial_No</Name>
    </Column>
    </Columns>
    </Row>
    <Row>
    <Columns>
    <Column>
    <Value>CF000008</Value>
    <Name>Serial_No</Name>
    </Column>
    </Columns>
    </Row>
    </Rows>
    </ResultSet>
    </ResultSets>
    </ExecuteDataSourceResult>
    </ExecuteDataSourceResponse>
    </soap:Body>
    </soap:Envelope>
    Text1.text shows the below information, I can't get the other Serial_No?
    CF000007
    CF000007

  2. #2
    *squeak*
    Bat's Avatar
    Joined
    Nov 2012
    Posts
    4,040
    Userbars
    152
    Thanks
    2,147
    Thanked
    46,688/3,563
    DL/UL
    34/1
    Mentioned
    1,769 times
    Time Online
    644d 1h 41m
    Avg. Time Online
    3h 41m
    Sorry about the misdirect, @(you need an account to see links)! Try changing this:

    Code:
    Text1.Text = objNode.selectSingleNode("//Column[Name='Serial_No']/Value").xml & vbCrLf & Text1.Text
    to this:

    Code:
    Text1.Text = objNode.xml & vbCrLf & Text1.Text
    Last edited by Bat; 03-22-2019 at 08:49 AM.

  3. The Following User Says Thank You to Bat For This Useful Post:

    Soredavide (03-22-2019)

  4. #3

    Joined
    Dec 2011
    Posts
    151
    Userbars
    2
    Thanks
    4
    Thanked
    165/45
    DL/UL
    14/9
    Mentioned
    68 times
    Time Online
    6d 17h 26m
    Avg. Time Online
    2m
    Wow, that was easy. Thanks. I wish I new a little more about reading XML.

    ---------- Post added at 10:53 AM ---------- Previous post was at 10:20 AM ----------

    Is it possible to split all Values and Names into an array, something that can be used later?

    <Value>CF000007</Value>
    <Name>Serial_No</Name>

    <Value>CF000008</Value>
    <Name>Serial_No</Name>

  5. #4
    *squeak*
    Bat's Avatar
    Joined
    Nov 2012
    Posts
    4,040
    Userbars
    152
    Thanks
    2,147
    Thanked
    46,688/3,563
    DL/UL
    34/1
    Mentioned
    1,769 times
    Time Online
    644d 1h 41m
    Avg. Time Online
    3h 41m
    Quote Originally Posted by Soredavide View Post
    Wow, that was easy. Thanks. I wish I new a little more about reading XML.

    ---------- Post added at 10:53 AM ---------- Previous post was at 10:20 AM ----------

    Is it possible to split all Values and Names into an array, something that can be used later?

    <Value>CF000007</Value>
    <Name>Serial_No</Name>

    <Value>CF000008</Value>
    <Name>Serial_No</Name>
    Sure! Your "objNodelist" will need to look like this:
    Code:
    Set objNodelist = objDoc.selectNodes("//Column[Name='Serial_No']")
    This will select the "Column" node instead just the "Value" node inside.

    Next, change your "Text1.Text" propagator to:
    Code:
    Text1.Text = (Text1.Text & objNode.childNodes.item(0).xml & vbCrLf & objNode.childNodes.item(1).xml & vbCrLf)
    This will read-in the "Column" node's "Value" and "Name" nodes in the order that you specified above.

    If you want the "Column" node itself and not just its children, then you can change your propagator to:
    Code:
    Text1.Text = (Text1.Text & objNode.xml & vbCrLf)
    This will include the "Column" node along with everything inside it.

  6. #5

    Joined
    Dec 2011
    Posts
    151
    Userbars
    2
    Thanks
    4
    Thanked
    165/45
    DL/UL
    14/9
    Mentioned
    68 times
    Time Online
    6d 17h 26m
    Avg. Time Online
    2m
    Text1.Text = (Text1.Text & objNode.childNodes.item(0).xml & vbCrLf & objNode.childNodes.item(1).xml & vbCrLf)
    objNode.childNodes. does not allow item do you have to assign objNode as array at some point?

  7. #6
    *squeak*
    Bat's Avatar
    Joined
    Nov 2012
    Posts
    4,040
    Userbars
    152
    Thanks
    2,147
    Thanked
    46,688/3,563
    DL/UL
    34/1
    Mentioned
    1,769 times
    Time Online
    644d 1h 41m
    Avg. Time Online
    3h 41m
    Quote Originally Posted by Soredavide View Post
    objNode.childNodes. does not allow item do you have to assign objNode as array at some point?
    objNode is an (you need an account to see links) object, and the (you need an account to see links) property should be an (you need an account to see links). I'm retrieving the "Name" and "Value" child nodes of objNode (which is a "Column" node), then I'm retrieving their (you need an account to see links) property while separating them with a new line in order to make the output look like what you mentioned above. Are you experiencing any errors with that, or do you not like the formatting?

  8. #7

    Joined
    Dec 2011
    Posts
    151
    Userbars
    2
    Thanks
    4
    Thanked
    165/45
    DL/UL
    14/9
    Mentioned
    68 times
    Time Online
    6d 17h 26m
    Avg. Time Online
    2m
    Text1.Text = (Text1.Text & objNode.childNodes.item(0).xml & vbCrLf & objNode.childNodes.item(1).xml & vbCrLf)
    objNode.childNodes. does not allow item do you have to assign objNode as array at some point?

    I don't get any autofill after objNode.childnode. and if I use that code I get function of interface marked as restricted or the function uses an automation type not supported in Visual Basic

  9. #8
    *squeak*
    Bat's Avatar
    Joined
    Nov 2012
    Posts
    4,040
    Userbars
    152
    Thanks
    2,147
    Thanked
    46,688/3,563
    DL/UL
    34/1
    Mentioned
    1,769 times
    Time Online
    644d 1h 41m
    Avg. Time Online
    3h 41m
    Quote Originally Posted by Soredavide View Post
    objNode.childNodes. does not allow item do you have to assign objNode as array at some point?

    I don't get any autofill after objNode.childnode. and if I use that code I get function of interface marked as restricted or the function uses an automation type not supported in Visual Basic
    I wasn't able to replicate that issue, but perhaps this will work for you instead:
    Code:
    Text1.Text = (Text1.Text & objNode.selectSingleNode("Value").xml & vbCrLf & objNode.selectSingleNode("Name").xml & vbCrLf)

  10. #9

    Joined
    Dec 2011
    Posts
    151
    Userbars
    2
    Thanks
    4
    Thanked
    165/45
    DL/UL
    14/9
    Mentioned
    68 times
    Time Online
    6d 17h 26m
    Avg. Time Online
    2m
    That worked, I actually went with objNode.parentNode.parentNode.Text. This gives me everything in the Node textwise, the XML I posted was just a tiny sample (the One I am actually using is a lot bigger and I am doing some comparisons, before selecting a serial number).

    Thanks again Odd (I am finally starting to understand XML "a little")

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •