Reading Multiple XML nodes

TheWizardofInt

Well-known member
Joined
Dec 31, 1969
Messages
333
Location
Orlando, FL
I have a stream to read, which is like this:

<Import>
<Name>Fred Jones</Name>
<Address>101 Main Street</Address>
</Import>
<Import>
<Name>Fred Smith</Name>
<Address>103 Front Street</Address>
</Import>


Obviously it is more complicated than that - I just have to read the first import then the next, into multiple datasets.

If I dont know for sure that the first Node will be Import (it could be Imports, Data, Feed, Contact) how can I tell the thing to take all of the Nodes with the start item of whatever and read them?
 
with an xml structure of:

<Root>
<Import>
<Name>Fred Jones</Name>
<Address>101 Main Street</Address>
</Import>
<Import>
<Name>Fred Smith</Name>
<Address>103 Front Street</Address>
</Import>
</Root>

Code:
Imports System.Xml

Dim xmld As XmlDocument
Dim ImportNode As XmlNode
Dim KeyNode As XmlNode
Dim nodelist As XmlNodeList

Link to XML document
xmld = New XmlDocument()
xmld.Load(ftp_files_dd.SelectedItem.Value & "/ImageKeys.Xml")

Get the list of Import nodes
nodelist = xmld.SelectNodes("/Root/Import")

For Each ImportNode In nodelist
     Get attribute by using:
     MyVar = ImageNode.Attributes.GetNamedItem("MyAttributeName").Value

    ..... Your code .....

        For Each KeyNode In ImageNode.ChildNodes
                Get sub node values here by using:
                 KeyValueVar = KeyNode.InnerText

                ..... Your code .....
        Next

Next

Not sure if this is what you were looking for, but maybe it will help..?
 
Thanks for replying.

No, that is what I am already doing.

When it gets t the second instance of the datastream, it happily goes on and adds it to the first stream
 
Maybe you could provide a more complex XML structure - so that we can understand your problem more clearly?
 
Back
Top