0

Good morning all.

I'm relatively new to the Visual Basic realm (although a traditional web based script developer), i've come to ask you a question. I am reading data from an XML file. This local XML file will be updated by another application, and I will need to periodically re-evaluate the XML file, and only import new data into a list box. Furthermore, I want to be able to click on a particular item in the listbox, and display the other values about that particular XML entry.

So, I suppose this is a multi part question. What is the proper way to import only NEW data into the program, what is the proper way to store the data, and how do I associate a value in a listbox with the data stored elsewhere?

I've considered multidimensional arrays, but have been told that strings to char arrays and then back to strings is a terrible way to manage the data, but was never offered an alternative.

I will be satisfied with a list of topics to study up on and/or an example for an answer to this question.

2 Answers2

0

As a start look at the XmlDocument and XmlReader classes.

XmlDocument helps load a document into memory and allows you to look at the document in any way you desire, depending on the size of the file there may be implications as to how long pulling in the file takes

XmlReader allows access on the fly, and gives you access very much like a DataReader. I.e. keeping track of your position in the dataset and not retaining any data once you have inspected it.

For keeping a track of updates, it depends where the XML is stored. If it is in a file a FileSystemWatcher may help in determining when you need to update....

brumScouse
  • 3,166
  • 1
  • 24
  • 38
  • when I say anyway you desire I mean by using the API and XPath – brumScouse Nov 03 '10 at 20:35
  • Aye, i've been using XmlReader and XmlDocument respectively. My difficulty comes in retaining that data, and linking what is put into the listbox to values. Where do I STORE, the data. Create classes? Multidimensional arrays? Output a NEW XML file, and read/write from that? – The Admiral Nov 03 '10 at 20:37
  • Sorry mate, kind of misread the question then. You might like to identify what it is you need to get out of the XML docs and slap them into some Classes/models. As long as your "querying" (can even do this using Linq to XML if desired) into the doc is pretty robust you should be able to get out the bits you need time after time. – brumScouse Nov 03 '10 at 20:45
  • If the Xml doc is big you might like to chop it up or even transform it using Xslt to get just the information you need. At some point you will alawys need to read in the info though. – brumScouse Nov 03 '10 at 20:47
0

I would probably use classes that implement INotifyPropertyChanged and a BindingList. Then you just need to listen to ListChanged events off of the list and update the list box then.

I have a blog post that discusses binding classes and interfaces if you want to learn more about them: Data Binding Classes, Interfaces, and Attributes in Windows Forms 2.0. It might be a little dated by now, I haven't reviewed it since I wrote it in March, 2007.

Brian
  • 37,399
  • 24
  • 94
  • 109