假如我们现在有这样的一个文件food.tab
内容如下:
Room_Number Breakfast Lunch Dinner
290 Bagel Pizza Salmon
301 Orange Pizza Chicken ala King
349 Sweet Roll Salad Tofu and Vegetables
500 Omelet Sausage Veal
702 Eggs Tuna fish Cheese Sandwich
文件中每一项都是用vbtab进行分割的
那么现在我们要把它自动转化为一个如下的xml文件
<Kitchen xmlns="The_Roach_Motel">
<Room_Service>
<Room_Number>290</Room_Number>
<Breakfast>Bagel</Breakfast>
<Lunch>Pizza</Lunch>
<Dinner>Salmon</Dinner>
</Room_Service>
<Room_Service>
<Room_Number>301</Room_Number>
<Breakfast>Orange</Breakfast>
<Lunch>Pizza</Lunch>
<Dinner>Chicken ala King</Dinner>
</Room_Service>
<Room_Service>
<Room_Number>349</Room_Number>
<Breakfast>Sweet Roll</Breakfast>
<Lunch>Salad</Lunch>
<Dinner>Tofu and Vegetables</Dinner>
</Room_Service>
<Room_Service>
<Room_Number>500</Room_Number>
<Breakfast>Omelet</Breakfast>
<Lunch>Sausage</Lunch>
<Dinner>Veal</Dinner>
</Room_Service>
<Room_Service>
<Room_Number>702</Room_Number>
<Breakfast>Eggs</Breakfast>
<Lunch>Tuna fish</Lunch>
<Dinner>Cheese Sandwich</Dinner>
</Room_Service>
</Kitchen>
我们需要怎么做呢:
我们需要利用StreamReader来读取文件内容,存放到一个临时的dataset中,最后用dataset的getxml()来得到这个xml文件
LET'GO
code:
Imports System
Imports System.IO
Imports System.Collections
Imports System.Data
Imports System.Text
Module modXML
Sub Main()
Dim strXML As String
strXML = delimitedDataSet(vbTab, "c:/food.tab")
'你可能需要进行必要的修改
End Sub
Function delimitedDataSet(ByVal strDelimiter As String, _
ByVal strFilePath As String) As String
Dim oDS As New DataSet()
Dim strFields As String
Dim oTable