M
Mitchell Vincent
So I have some XML exported from another database. This is greatly
trimmed for brevity's sake..
<Customer>
<CustomerNumber>C1000</CustomerNumber>
<CustomerName>Demo Customer 1</CustomerName>
<CustCredit>
<Amount>1000</Amount>
</CustCredit>
</Customer>
I need to parse those and take into account that there might be an
unknown number of <CustCredit> elements, or none as the case may be.
This is how I'm starting - code idea ripped from some vb.net site :
Dim xmlr As XmlTextReader
'Create the XML Reader
xmlr = New XmlTextReader("export.xml")
xmlr.WhitespaceHandling = WhitespaceHandling.None
'read the xml declaration and advance to family tag
'xmlr.Read()
'read the family tag
'xmlr.Read()
'Load the Loop
While Not xmlr.EOF
'Go to the name tag
'if not start element exit while loop
If Not xmlr.IsStartElement() Then
Exit While
End If
MyCust.Number = xmlr.ReadElementString("CustomerNumber")
End While
'close the reader
xmlr.Close()
It simply doesn't work - or at least not in any way I can see it.
I'd like to have the ability to say "give me this field from the current
<Customer>, now look to see if there is a <CustCredit>, if so, loop
through and give me each of those fields..
Help!!
I have 13 (literally) VB.NET books and none of them give any useful real
world examples of how to read and parse XML!
Thanks!
trimmed for brevity's sake..
<Customer>
<CustomerNumber>C1000</CustomerNumber>
<CustomerName>Demo Customer 1</CustomerName>
<CustCredit>
<Amount>1000</Amount>
</CustCredit>
</Customer>
I need to parse those and take into account that there might be an
unknown number of <CustCredit> elements, or none as the case may be.
This is how I'm starting - code idea ripped from some vb.net site :
Dim xmlr As XmlTextReader
'Create the XML Reader
xmlr = New XmlTextReader("export.xml")
xmlr.WhitespaceHandling = WhitespaceHandling.None
'read the xml declaration and advance to family tag
'xmlr.Read()
'read the family tag
'xmlr.Read()
'Load the Loop
While Not xmlr.EOF
'Go to the name tag
'if not start element exit while loop
If Not xmlr.IsStartElement() Then
Exit While
End If
MyCust.Number = xmlr.ReadElementString("CustomerNumber")
End While
'close the reader
xmlr.Close()
It simply doesn't work - or at least not in any way I can see it.
I'd like to have the ability to say "give me this field from the current
<Customer>, now look to see if there is a <CustCredit>, if so, loop
through and give me each of those fields..
Help!!
I have 13 (literally) VB.NET books and none of them give any useful real
world examples of how to read and parse XML!
Thanks!