Looking for a better way to search & transfer information between DataSets and XmlDataDocuments

  • Thread starter Thread starter David Elliott
  • Start date Start date
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
 
Hi David,

In addition to your approach, I think you may try to use the xslt file to
do the replace job.
XSLT Transformations with the XslTransform Class
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/htm
l/cpconXSLTTransformationsWithXslTransformClass.asp

Here is a good start.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/xmlsdk/html
/XSLT_What_Is_XSLT.asp

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Back
Top