I am creating two services. One downloads XML streams from WebSphere MQ into
a SQL2K database, the other uploads XML Streams into Websphere MQ from
SQL2K. The upload service polls SQL2K every couple of minutes for uploads.
If there are uploads I create an ADO Dataset that I must convert to an XML
stream. The Dataset and the XML stream have different schemas, just to
clarify my dilema. I'm seeking input on the best way to convert ADO Datasets
to XML streams and vice versa, baring in mind their schemas are different. I
did a POC and "hard coded" each field to it's element. Surely, there's
another way. I have several of these to do and most have well over 100
fields. It would be nice to iterate through either the .xsd or the empty
.xml, and fill the .xml, utilizing a .xml based map, with the fields in the
ADO dataset. I am comfortable with the Document and Schema Object Models.
Any recommendations would be welcomed. Thanks in advance for your time.
You can extract an XmlDocument from the DataSet, and can then apply an XSL
transform on it.
And of course, you can do the converse, too. examples:
http://samples.gotdotnet.com/quickstart/howto/doc/Xml/LoadXmlDocument.aspx
Have you tried this?
If you want to avoid the dataset and XSL on the DB-to-MQ path, there is an
FOR XML support in SQL2000, which allows you to extract whatever shape of
XML you like from a query. You can do something like this:
System.Xml.XmlTextReader xtr= null;
System.Xml.XmlDocument doc= null;
System.Data.SqlClient.SqlConnection dbconn= null;
try {
dbconn= GetDbConn();
System.Data.SqlClient.SqlCommand cmd= new
System.Data.SqlClient.SqlCommand(strSQL, dbconn);
cmd.Connection.Open();
xtr = (System.Xml.XmlTextReader) cmd.ExecuteXmlReader();
//xtr.WhitespaceHandling = System.Xml.WhitespaceHandling.None;
doc = new System.Xml.XmlDocument();
doc.Load(xtr);
//do whatever you like here
}
....
The FOR XML EXPLICIT can do basically what you describe here:
> It would be nice to iterate through either the .xsd or the empty .xml, and
> fill the .xml, utilizing a .xml based map, with the fields in the ADO
> dataset.
...but it is being done by SQL Server. The query strings can get pretty
ugly, though. See here for some help and examples:
http://www.topxml.com/sql/for_xml_explicit.asp
Regardless how you get it, once you have the XmlDocument you can transform,
serialize, whatever.
-D
>I am creating two services. One downloads XML streams from WebSphere MQ
>into a SQL2K database, the other uploads XML Streams into Websphere MQ from
[quoted text clipped - 10 lines]
>Models. Any recommendations would be welcomed. Thanks in advance for your
>time.