Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...An excellent site which has quite possibly prevented me from having a mental/nervous breakdown..."

Geography

Where in the world do Tek-Tips members come from?

problem getting multiple column of a xml fileHelpful Member! 

baran121 (Programmer)
12 Jul 12 10:25
hi there, i have following xml file.
i want to get data from this xml to my visual basic 6 program.
i try to use this:

Set oparser = CreateObject("msxml2.domdocument")
bRet = oparser.loadXML(str_xml)

If bRet Then
For i = 0 To celemi6.Length - 1
For j = 0 To celemi6(i).Attributes.Length - 1
MsgBox celemi6(i).Attributes.getNamedItem("PartNumber").Text
Next
Next
end if

but there is a problem, because i cant get sub info from xlm file.
just first <PartInfo>
i wanna get data all <PartInfo> for each <Plan>
i need your help,
thank you...

<Plan>
<VehicleInfo>
<VehicleGroup>BUS</VehicleGroup>
<VehicleCode>BA23K126</VehicleCode>
<Chassis>A235734</Chassis>
<ShipTo>G03</ShipTo>
<DueDate>10/07/2012</DueDate>
<Note>PP:201217|T3 Date:24/05/2012|Fassung Date:24/05/2012|Production Sequence:2|Customer:MAN KAMYON VE OTOBUES TIC. A.S|Country:TR</Note>
</VehicleInfo>
<PartInfo>
<PartNumber>88.76240.0030</PartNumber>
<PartDescription>BAGLANTI CITASI</PartDescription>
<SupplierPartNumber/><SupplierPartDescription/>
<Consignment>Hayır</Consignment>
<Quantity>4</Quantity>
<PartNote>:078ET-Tutamaklar sarı RAL 1018 toz kaplamalı#</PartNote>
</PartInfo>
<PartInfo>
<PartNumber>88.76240.6001</PartNumber>
<PartDescription>BAGLANTI CITASI</PartDescription>
<SupplierPartNumber/><SupplierPartDescription/>
<Consignment>Hayır</Consignment>
<Quantity>4</Quantity>
<PartNote>:078ET-Tutamaklar sarı RAL 1018 toz kaplamalı#</PartNote>
</PartInfo>
</Plan>
baran121 (Programmer)
15 Jul 12 18:19
actually i found following code i still need help :(
when i use the code, i see total data i need data seperately.
i need help please.


Set list = xmlDoc.selectNodes("//Plan")
For i = 0 To list.Length - 1
For j = 0 To list.Item(i).childNodes.Length - 1
msgbox list.Item(i).childNodes.Item(j).baseName
msgbox list.Item(i).childNodes.Item(j).nodeTypedValue
next
next

i got following
1. message box -VehicleInfo
2. message box - BUS BA23K126 A235736 D09 10/07/2012 PP:201217|T3 Date:24/05/2012|Fassung Date:24/05/2012|Production Sequence:3|Customer:MAN KAMYON VE OTOBUES TIC. A.S|Country:TR

and next
1. message box -PartInfo
2. message box -81.94297.0249 BORU Hayır 1 078ET-Tutamaklar sarı RAL 1018 toz kaplamalı#

i wanna get all data one by one.
i really need your help, thank you.
mikrom (Programmer)
16 Jul 12 9:44
Some times ago I posted here a little example how to parse XML in VBscript
http://www.tek-tips.com/viewthread.cfm?qid=1649062
In Visual Basic 6 it would be similar.
baran121 (Programmer)
16 Jul 12 10:28
thank you mikrom. but i think you misunderstood me.
because when i looked at your post (the link) it is different from that i wanted to do.
i ll try to explain more about it.

<VehicleInfo>
<VehicleGroup>BUS</VehicleGroup>
<VehicleCode>BA23K126</VehicleCode>
<Chassis>A235734</Chassis>
<ShipTo>G03</ShipTo>
<DueDate>10/07/2012</DueDate>
<Note>PP:201217|T3 Date:24/05/2012|Fassung Date:24/05/2012|Production Sequence:2|Customer:MAN KAMYON VE OTOBUES TIC. A.S|Country:TR</Note>
</VehicleInfo>

i ll get this data in a master table to my database



<PartInfo>
<PartNumber>88.76240.0030</PartNumber>
<PartDescription>BAGLANTI CITASI</PartDescription>
<SupplierPartNumber/><SupplierPartDescription/>
<Consignment>Hayır</Consignment>
<Quantity>4</Quantity>
<PartNote>:078ET-Tutamaklar sarı RAL 1018 toz kaplamalı#</PartNote>
</PartInfo>
<PartInfo>
<PartNumber>88.76240.6001</PartNumber>
<PartDescription>BAGLANTI CITASI</PartDescription>
<SupplierPartNumber/><SupplierPartDescription/>
<Consignment>Hayır</Consignment>
<Quantity>4</Quantity>
<PartNote>:078ET-Tutamaklar sarı RAL 1018 toz kaplamalı#</PartNote>
</PartInfo>

these two <PartInfo> parts will be used in detail table to my database


so if i do this
Set list = xmlDoc.selectNodes("//Plan")
i got whole data not one by one

so if i do this
Set list = xmlDoc.selectNodes("//Plan/VehicleInfo")
i got data one by one but i cant make a relationship with <PartInfo>

so if i do this
Set list = xmlDoc.selectNodes("//Plan/PartInfo")
i got data one by one but i cant make a relationship with <VehicleInfo>

any hint please...










strongm (MIS)
16 Jul 12 10:50
Between the threads that you have asked about this we have shown how to parse XML nodes, any XML nodes, for both their data and attributes. It is unlikely that anyone is going to write your project for you, however. You should now have all the tools necessary to do this yourself. If not, please explain what you have tried so far, and in what way it is nt working for you. Then perhaps we can help further.
baran121 (Programmer)
16 Jul 12 13:10
thank you strongm ,
let me explain more about my problem.

<Plan>
<VehicleInfo>
this data is for the master table (between <VehicleInfo> and </VehicleInfo> )
</VehicleInfo>
<PartInfo>
this data is my first data for the datail table (between <PartInfo> and </PartInfo> )
</PartInfo>
<PartInfo>
this data is my second data for the datail table (between <PartInfo> and </PartInfo> )
</PartInfo>
</Plan>




so if i do this
Dim fso As FileSystemObject
Dim xmlDoc As MSXML.DOMDocument
Dim xmlFileName As String
Dim list As IXMLDOMNodeList
Dim i As Integer, j As Integer

Set fso = New FileSystemObject
xmlFileName = "D:\DATASET\vSRMBuildToOrderList_20120709081103.xml"
If fso.FileExists(xmlFileName) Then
Set xmlDoc = New MSXML.DOMDocument
xmlDoc.Load (xmlFileName)
Else 'if there is no xml file
Exit Sub
End If

Set list = xmlDoc.selectNodes("//Plan")
For i = 0 To list.Length - 1
For j = 0 To list.Item(i).childNodes.Length - 1
base = list.Item(i).childNodes.Item(j).baseName
MsgBox base '1. msgbox
MsgBox list.Item(i).childNodes.Item(j).nodeTypedValue '2.msgbox
next
next

'for first j (j=0) this gives me that
'1.msgbox : VehicleInfo
'2.msgbox : BUS BA23K126 A235734 G03 10/07/2012 PP:201217|T3 Date:24/05/2012|Fassung Date:24/05/2012|Production Sequence:2|Customer:MAN KAMYON VE OTOBUES TIC. A.S|Country:TR

'for second j (j=1) this gives me that
'1.msgbox : PartInfo
'2.msgbox : 88.76240.0030 BAGLANTI CITASI Hayır 4 078ET-Tutamaklar sarı RAL 1018 toz kaplamalı#


'for 3. j (j=2) this gives me that
'1.msgbox : PartInfo
'2.msgbox : 88.76240.6001 BAGLANTI CITASI Hayır 4 078ET-Tutamaklar sarı RAL 1018 toz kaplamalı#


i want to get data like following:
VehicleGroup: BUS
VehicleCode: BA23K126
Chassis: A235734
ShipTo: G03
DueDate: 10/07/2012
PartNumber: 88.76240.0030
PartDescription: BAGLANTI CITASI
Quantity: 4
PartNote: 078ET-Tutamaklar sarı RAL 1018 toz kaplamalı#
PartNumber: 88.76240.6001
PartDescription:BAGLANTI CITASI
Quantity: 4
PartNote: 078ET-Tutamaklar sarı RAL 1018 toz kaplamalı#


Helpful Member!  strongm (MIS)
16 Jul 12 14:18
>let me explain more about my problem

I understood your basic problem. What I don't understand is how, given the answers you got so far, you have been unable to extrapolate to a suitable solution. For example:

CODE

Option Explicit

Private Sub CommandButton1_Click()
    Dim oParser As DOMDocument
    Dim Nodes As Object
    Dim MyNode As IXMLDOMNode
    
    Set oParser = New DOMDocument
    oParser.LoadXML Text1.Text
    
    For Each MyNode In oParser.ChildNodes
        ScanNodes MyNode, 0
    Next
End Sub

Private Sub ScanNodes(SourceNode As IXMLDOMNode, ByVal Indent As Long)
    Dim MyNode As IXMLDOMNode

    If SourceNode.NodeType <> NODE_ELEMENT Then
    Debug.Print ": " & SourceNode.NodeValue;

    Else
        Debug.Print
        Debug.Print String$(Indent, vbTab) & SourceNode.BaseName;
        Indent = Indent + 1
        For Each MyNode In SourceNode.ChildNodes
            ScanNodes MyNode, Indent
        Next
    End If
    
End Sub
 
baran121 (Programmer)
17 Jul 12 17:23
thank you strongm very much.
you solved all my problem.
thanks again.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close