Creating and populating array from XML

  • Thread starter Thread starter Aaron
  • Start date Start date
A

Aaron

Can anyone point me in the right direction here. I don't need anything
complicated, all I want is to populate an array with fields from an XML
file. I have a small XML file with about 12 records and each record has 4
fields. I need to create an array which holds only three of those fields
from each record, so a 1 x 3 array I'm assuming. Is there a simple way to
set this up, or does someone have an example of this that I could use?

Thanks
 
In most cases XML parsing is not a generic process, so if you want somebody
to help you with that you could post at least your XML. Otherwise, take a
look at XmlTextReader in the docs and web for samples.
 
The XML is very simple, here's what it looks like with one record:

<?xml version="1.0" encoding="utf-8" ?>
<Pain_Medications>
<Medications>
<Drug>Codeine</Drug>
<Parenteral>130.00</Parenteral>
<Oral>200.00</Oral>
<Comment>Codeine is usually combined with Tylenol or aspirin, and that is
the limiting factor in the dosage of this drug.
</Medications>
</Pain_Medications>

What I need are the Drug, Parenteral, and Oral fields read into the array
and in that order. Like I mentioned, I have about 12 records, not that that
matters.
 
Aaron...we have a fairly complex set of different XML records with multiple
nodes/data elements in each. I have attached one of the more complex ones
to perhaps give you some idea of the type of call you need. I have removed
some of the code just to simplify...let me know if this needs more
explanation...xtrMove is an 'extended' xtr.read that let's us do some common
data validation. Your routine won't need this complexity, but the general
structure should pretty much be the same...sorry if this is more than you
wanted!


' OPEN THE FILE
Dim xtr As New XmlTextReader(templatename)

' READ IT ALL INTO MEMORY
Do While xtr.Read
Select Case xtr.NodeType
Case XmlNodeType.Element
Select Case xtr.Name
Case "GroupName1"
xtrMove(myGroupName1, xtr, 0)
Case "GroupName2"
xtrMove(myGroupName2, xtr, 0)
Case "GroupName3"
xtrMove(myGroupName3, xtr, 0)
Case "GroupName4"
xtrMove(myGroupName4, xtr, 0)
Case "AmountIndex"
xtrMove(myAmountIndex, xtr, 1)
Case "DiscountIndex"
xtrMove(myDiscountIndex, xtr, 1)
Case "BookDateIndex"
xtrMove(myBookDateIndex, xtr, 1)
 
Back
Top