views:

273

answers:

2

Using VB.net (.net 2.0) I have a string in this format:

record1_field1,record1_field2,record2_field3,record2_field1,record2_field2,

etc...

I wonder what the best (easiest) way is to get this into an xml?

I can think of 2 ways:

Method 1: - use split to get the items in an array - loop through array and build an xml string using concatenation

Method 2: - use split to get the items in an array - loops through array to build a datatable - use writexml to output xml from the datatable

The first sounds pretty simple but would require more logic to build the string.

The second seems slicker and easier to understand.

Are there other ways to do this?

+1  A: 

Instead of doing string concatenation, you could probably create an XmlDocument and stuff it with the appropriate XmlElement and XmlAttribute objects from your string... Then, write out the XmlDocument object...

Joe The Software Developer
+2  A: 
mmattax
look at his sample more carefully: there's some nesting going on there this won't account for.
Joel Coehoorn
I chose this as answer because it gives me a good idea of how to start. Joe's answer also helped, but this one is more complete. And thanks to Joel for pointing out additional things to consider.
metanaito