Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem getting multiple column of a xml file 1

Status
Not open for further replies.

baran121

Programmer
Sep 8, 2005
337
TR
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>
 
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.
 
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...










 
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.
 
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ı#


 
>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:
[blue]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
[/blue]
 
thank you strongm very much.
you solved all my problem.
thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top