PC Review


Reply
Thread Tools Rate Thread

Creating and populating array from XML

 
 
Aaron
Guest
Posts: n/a
 
      23rd Nov 2004
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


 
Reply With Quote
 
 
 
 
=?Utf-8?B?QWxleCBZYWtobmluIFtNVlBd?=
Guest
Posts: n/a
 
      23rd Nov 2004
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.

--
Alex Yakhnin, .NET CF MVP
www.intelliprog.com
www.opennetcf.org

"Aaron" wrote:

> 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
>
>
>

 
Reply With Quote
 
Aaron
Guest
Posts: n/a
 
      23rd Nov 2004
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.

"Alex Yakhnin [MVP]" <(E-Mail Removed)> wrote in message
news:9539C640-D97A-47BA-ADC5-(E-Mail Removed)...
> 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.
>
> --
> Alex Yakhnin, .NET CF MVP
> www.intelliprog.com
> www.opennetcf.org
>
> "Aaron" wrote:
>
> > 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
> >
> >
> >



 
Reply With Quote
 
Glyn Meek
Guest
Posts: n/a
 
      24th Nov 2004
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)
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Populating an array Bucs85027 Microsoft Excel Worksheet Functions 0 14th Feb 2008 12:32 AM
Populating an array<System::UInt32>^ from an unmanaged array in the new C++/CLI syntax Bern McCarty Microsoft VC .NET 2 21st Dec 2006 05:14 AM
Error populating array =?Utf-8?B?YW1iZXI=?= Microsoft Dot NET 2 25th Sep 2005 03:47 PM
Populating an Array Wayne Wengert Microsoft VB .NET 1 24th Jan 2005 02:05 PM
Populating a 2-D array Hotbird Microsoft Excel Programming 9 7th Feb 2004 05:25 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:50 AM.