GJohnston

I have a VERY simple XML file that will basically contain a list which i need to use as the Items in a combo box... the XML file looks like this

< xml version='1.0' encoding='utf-8' >
<!-- The List of Resets Currently On Going -->
<resets
title="Reset Index List"
date="08092007"
author="Gene Johnston">
<!-- RESET LIST -->
<ITEM> TEST1 </ITEM>
<ITEM> TEST2 </ITEM>
<item> TEST3 </item>

</resets>

What i need to do is simply get the variables (i.e. TEST1, TEST2, TEST3) and save them into variables i guess and then I need to be able ot populate a combo box's items from this list. I'm not sure if it's even possible considering I keep getting a read-only error when i try to modify a combo box's items at runtime...but i guess what i need out fo you guys is a simple procedure to get these items and store them into an array of variables...thanks so much!

PS: here's a small snippet of my code that I'm currently using just to open the document

Public Sub LoadReset()

Dim textReader As XmlTextReader = New XmlTextReader("\PicturePilot\reset.xml")

textReader.Read()

If textReader.HasValue Then

While textReader.Read()

Debug.WriteLine(textReader.ReadElementContentAsString)

End While

End If




Re: XML and the .NET Framework Simple question Im sure

Sergey Dubinets - MSFT

You need to check where your reader is position by comparing reader.LocalName and reader.NamespaceURI properties to whatever you expect ("ITEM" and "" in your sample).

XmlReader would stop on comments (<!-- -->) and may be whitespaces. It is not good practice call Read() several times and expect that reader is on correct position.






Re: XML and the .NET Framework Simple question Im sure

GJohnston


after researching again as to what i really need, I think i'm going to need something a little more complex than i had originally thought. I need a simple heirarchy i think...2 levels deep.

  • <RESET>TESTRESET1</RESET>
    • <STORE>STOREA1</STORE>
    • <STORE>STOREA2</STORE>
    • <STORE>STOREA3</STORE>
    • <STORE>STOREA4</STORE>
  • <RESET>TESTRESET2</RESET>
    • <STORE>STOREB1</STORE>
    • <STORE>STOREB2</STORE>
    • <STORE>STOREB3</STORE>
  • <RESET>TESTRESET3</RESET>
    • <STORE>STOREC1</STORE>



Something more like that would really work for me better int he long run....problem is, I need to be able to populate variable based on the data TESTRESET1, TESTRESET2, ect...and I need to know what "stores" belong to which "resets"....So I guess i need an array for the resets and an array of arrays for the stores I'm not sure how this should actually be acomplished and I'm sure it's been done before..however..I'm not very familiar with XML and the Compact Framework has been giving me headaches since i started using it. Thanks so much, and example code or snippets is much apreciated.





Re: XML and the .NET Framework Simple question Im sure

BHF

Have a look at XPath queries - a good tutorial can be found at http://www.w3schools.com/xpath/

Also, you're structure needs a little work - you're making you're life difficult with the one you suggested.

I would suggest a structure along the lines of:

<reset type="testReset1">
<store>StoreA1</store>
<store>StoreA2</store>
</reset>
<reset type="testReset2">
<store>StoreB1</store>
<store>StoreB2</store>
</reset>

You can then use the SelectNodes method (on any XmlDocument or XmlNode variable) and pass in your XPath query (something along the lines of "/reset[@type='##VAR##]/store") which would return the list of store nodes where type = ##VAR##. Then you can iterate through them retrieving the InnerText for each node.