Dataset.ReadXML or ‘O Schema, Where Art Thou’
I’m still cranking ot XML by the bucket load and ran into an interesting solution to a problem using the datasets and readXML.
I wanted to use datasets rather than XPath or XMLDocument or any of the other readers. However, I was having trouble mapping the XML schema to the dataset paradigm in my mind. So I found this niffty piece of code and tweaked it. It helped me a lot!
Public Sub PrintDataSet(ByVal ds As DataSet)
‘ make an output file for the schema
Dim fn As String = Request.PhysicalApplicationPath + “\theOutputfile.txt”
Dim dw As StreamWriter = New StreamWriter(fn)
‘ Print out all tables and their columns
For Each table As DataTable In ds.Tables
dw.WriteLine(“TABLE ‘{0}’”, table.TableName)
dw.WriteLine(“Total # of rows: {0}”, table.Rows.Count.ToString)
dw.WriteLine(“—————————————————————”)
For Each column As DataColumn In table.Columns
dw.WriteLine(column.ColumnName + “: ” + column.DataType.ToString())
Next ‘ For Each column dw.WriteLine(System.Environment.NewLine)
Next ‘ For Each table ‘ Print out table relations
For Each relation As DataRelation In ds.Relations
dw.WriteLine(“RELATION: {0}”, relation.RelationName)
dw.WriteLine(“—————————————————————”)
dw.WriteLine(“Parent: {0}”, relation.ParentTable.TableName)
dw.WriteLine(“Child: {0}”, relation.ChildTable.TableName)
dw.WriteLine(System.Environment.NewLine)
Next ‘ For Each relation dw.Close()
End SubThe output file looks like this xmldatasetprint.txt, which, believe it or not, makes a lot of sense too me
Related posts:


