Question XML and Datagridview

timh

Well-known member
Joined
Nov 28, 2008
Messages
50
Programming Experience
Beginner
Hello,

I am struggling with reading the contents of an XML file into a DataGridView control in Visual Basic (using Visual Studio 2005). Extensive searching on the internet and scouring through a couple of books on VB and XML have failed to find a result. The answer is probably out there, but I haven't found it yet!

The XML document contains a series of "waypoint" elements, as follows (omitting the headers)...

HTML:
<waypoint>
	<name id="GCVEAF"><![CDATA[Robin's Slippery Slope by robandtiina]]></name>
	<coord lat="51.835617" lon="-2.237067"/>
	<type>Geocache</type>
	<link text="Cache Details">http://www.geocaching.com/seek/cache_details.aspx?wp=GCVEAF</link>
</waypoint>
<waypoint>
	<name id="GC18XA3"><![CDATA[Sidetracked - Kidsgrove by The Bignall Boppers]]></name>
	<coord lat="53.0866" lon="-2.243883"/>
	<type>Geocache</type>
	<link text="Cache Details">http://www.geocaching.com/seek/cache_details.aspx?wp=GC18XA3</link>
</waypoint>

I can read the XML into a dataset, but because of the attributes, I end up with four different tables, each containing just one element. The four tables are:

waypoint, name, coord and link

waypoint has one column: "type"
name has two columns: "id" & "name_Text"
coord has two columns: "lat" & "lon"
link has two columns: "text" & "link_Text"

I can then display any one of these four tables in a datagridview, but obviously what I want is to be able to view the whole "waypoint" element in one row. If it wasn't for the presence of attributes, it would be a doddle, because there would only be one table, but unfortunately the XML format for the data is established and is what I have to work with. (I'm trying to create my own app for managing "Geocache" data, "Geocaching" being a little hobby of mine.)

I feel confident that there must be a straightforward solution, but despite spending hours poring over the Visual Studio documentation and searching the web, I haven't worked it out. I should perhaps add that I want to be able to write back to the file in the same "standard" format, e.g. if I add a new waypoint or edit an existing one.

Hopefully someone will have come across this scenario before, or be able to guide me in the right direction.

Many thanks,

Tim
 
OK. More reading suggested I was going about things the wrong way.

For anyone who may be interested, I resolved the problem by doing an XLS transform, reformatting the original XML to a format that reads straight into the datagridview control.

When I save the file again, I will obviously have to remember to apply a transform back to the original format.

It's a steep learning curve, but actually, XSLT seems pretty straightforward.

Thanks for the interest.
 
Back
Top