Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Xml with attributes into array

Status
Not open for further replies.

hatbocs

Programmer
Joined
Aug 8, 2007
Messages
1
Location
US
I'm trying to make a fairly simple inventory program that gets the data from xml.

Example of xml:
Code:
<?xml version="1.0" encoding="iso-8859-1"?>
<inventory>
	<category name="Bowls">
		<category name="B3x4.5LID2">
			<item code="B3x4.5LID2" desc="White Bowl w/ Lid 3x4.5" price="23.50" ondisplay="7/31/07" sold="no" />
			<item code="B3x4.5LID2" desc="White Bowl w/ Lid 3x4.5" price="23.50" ondisplay="7/31/07" sold="8/10/07" />
		</category>
		<category name="B4x5LID2">
			<item code="B4x5LID2" desc="Bowl w/ Lid 4x5" price="40.60" ondisplay="6/10/07" sold="no" />
			<item code="B4x5LID2" desc="Bowl w/ Lid 4x5" price="40.60" ondisplay="6/10/07" sold="no" />
			<item code="B4x5LID2" desc="Bowl w/ Lid 4x5" price="40.60" ondisplay="no" sold="no" />
			<item code="B4x5LID2" desc="Bowl w/ Lid 4x5" price="40.60" ondisplay="no" sold="no" />
			<item code="B4x5LID2" desc="Bowl w/ Lid 4x5" price="40.60" ondisplay="6/10/07" sold="6/20/07" />
			<item code="B4x5LID2" desc="Bowl w/ Lid 4x5" price="40.60" ondisplay="6/10/07" sold="6/20/07" />
		</category>
	</category>
</inventory>

Right now I'm planning on trying to get all of that information into an arraylist if I can. I'm sure what the best way to organize the array(s) as but I was thinking having an array within an array, if that's possible, with an array for each category of items.

Also what I would like to do with that array is display it in a treeview and when you click on a node the attributes in the xml (or array) will appear in text boxes.

I'm not exactly sure where to start in something like this. I can read the xml and put it in the tree directly but that only solves half of the problem.

Maybe there's a better way to organize my xml?

Thanks for any help.
 
Maybe I'm just a crazy guy, but I've never been a fan of storing data in attribute tags. I always figured they were there for meta data and that your data should be stored as data. But that's just me ;)

Anyways, if you have control of the XML structure, the easiest solution is to use the DataSet object. It has a .ReadXML and .WriteXML. Unfortunately, it doesn't do well with data stored in attribute tags, so if the sample you posted is the structure you have to work with, it won't do you much good.

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top