D
David Elliott
I am scraping a database to create a XSD file that will be used to create typed DataSets. In
doing this I am adding a mapping capability to rename the field names from the Database
column name to a user friendly name.
The approach I have taken is to get the schema using DataAdapter.FillSchema() and then
passing it to a XmlDataDocument
dataAdapter.FillSchema(ds, SchemaType.Source);
xmlDataDoc = new XmlDataDocument ( );
xmlDataDoc.LoadXml ( ds.GetXmlSchema() );
xmlDataDoc.Normalize ( );
After I have the XmlDataDocument, I can use XmlNode.SelectNodes() and
XmlNode.SelectSingleNode() to find particular nodes. And using my map file I can
annotate the node with a new name.
After this is done, I want to have pretty formatting in order to write the schema to disk.
To do this I recreate the DataSet from the XmlDataDocument.
DataSet ds = new DataSet();
MemoryStream ms = new MemoryStream ( Encoding.Unicode.GetBytes ( xmlDoc.OuterXml ) );
ms.Position = 0;
ds.ReadXmlSchema(ms);
While this works, I was wondering if there is a better way to
-- Search
-- Retain Formatting
-- Access the data in the XmlDataDocument
Any thoughts are appreciated.
Cheers,
Dave
doing this I am adding a mapping capability to rename the field names from the Database
column name to a user friendly name.
The approach I have taken is to get the schema using DataAdapter.FillSchema() and then
passing it to a XmlDataDocument
dataAdapter.FillSchema(ds, SchemaType.Source);
xmlDataDoc = new XmlDataDocument ( );
xmlDataDoc.LoadXml ( ds.GetXmlSchema() );
xmlDataDoc.Normalize ( );
After I have the XmlDataDocument, I can use XmlNode.SelectNodes() and
XmlNode.SelectSingleNode() to find particular nodes. And using my map file I can
annotate the node with a new name.
After this is done, I want to have pretty formatting in order to write the schema to disk.
To do this I recreate the DataSet from the XmlDataDocument.
DataSet ds = new DataSet();
MemoryStream ms = new MemoryStream ( Encoding.Unicode.GetBytes ( xmlDoc.OuterXml ) );
ms.Position = 0;
ds.ReadXmlSchema(ms);
While this works, I was wondering if there is a better way to
-- Search
-- Retain Formatting
-- Access the data in the XmlDataDocument
Any thoughts are appreciated.
Cheers,
Dave