files and arrayList

Signo.X

Well-known member
Joined
Aug 21, 2006
Messages
76
Location
Australia
Programming Experience
1-3
Hello all,

Im trying to read the data from a text file into an arrayList, split them then create an xml document based on the data read from the .txt.

the .txt file could have the following data :
1
p2
3
...

to create the xml document, im using the xml class in vb.net
system.xml..

i have a problem with getting the loop logic to work the way i want it..
i.e. i want it to replace every item in xml file in the same order im reading them from the txt file...

thats what i have for now...

For i = 0 To arrList.count() - 1

xtw.WriteElementString("ORDERNO", arrList(i))
xtw.WriteElementString("custcode".ToUpper, arrList(i))
xtw.WriteElementString("custPart".ToUpper, arrList(i))
etc...
next

i want the the current index i to increment for every element .. rather than repeat every element..

can any one help ?

Thanks in advanced!
'Signo.X
 
Last edited:
Dont use a loop, create your xml document like this

xtw.WriteElementString("ORDERNO", arrList(0))
xtw.WriteElementString("custcode".ToUpper, arrList(1))
xtw.WriteElementString("custPart".ToUpper, arrList(2))

or if you have multiple objects you want in the same xml document you should create a small class to hold your properties then add a new instance of that class to your arraylist and then use your loop to add the elements for each object.
 
thanks for the reply,,

'Dont use a loop, create your xml document like this'

i did that, but then i'l have another problem, As im dealing with different files, it wont be always 3 emlements , so if the file have less than 3 values i'll have index out of bound exception.!!!

xtw.WriteElementString("ORDERNO", arrList(0))
xtw.WriteElementString("custcode".ToUpper, arrList(1))
xtw.WriteElementString("custPart".ToUpper, arrList(2))

so i want something to keep track of the arrList size which could be done by arList.cout() but then how i can increamt the index automaticaly at the same time ?

~signo.x
 
In that case you could use a sorted list collection, that will allow you to add a key (xml element name) and a value. then simply loop through that collection and add the key/value pairs to the xml document

for example...

Dim col as new Collections.Generic.SortedList(Of String, String)

add your items like this...
col.add(key, value)

now just loop through the collection and create the xml document like this...

for each key as string in col.Keys
xtw.WriteElementString(key, col.Item(key))
next
 
The solution was easier than i expected ,. thats all what i wanted to do...
while ( i < arrList.count()-1)
xtw.WriteElementString("ORDERNO", arrList(i))
i += 1
xtw.WriteElementString("custcode".ToUpper, arrList(i))
i+=1
end while
took heaps of time, but at the end..just a silly logic problem
thanks all

~signo.X
 
Last edited:
Back
Top