How to use a XML/XSD Schema with a Stored Procedure based Query...

Topics: Data Access Application Block
Nov 21, 2010 at 2:55 PM

Thank you in advance to anyone that can help me with this.  I am executing a stored procedure to collect results from multiple tables in a manner such as:  

CREATE PROCEDURE mySP ()
AS
SELECT * FROM See
SELECT * FROM Spot
SELECT * FROM Run

This works fine and I can get a DataSet from the result.  I then take that data and convert it to XML and would like to use the DataSet.GetXML() method.  The problem is that the default output format it returns is like this (note that I am able to change the table names and the default element name):

<MyDataSet>
   <See>
      columns...
   </See>
   <Spot>
      columns...
   </Spot>
   <Run>
      columns...
   </Run>
   <Run>
      columns...
   </Run>
   <Run>
      columns...
   </Run>
   <Run>
      columns...
   </Run>
   <Run>
      columns...
   </Run>
</MyDataSet>

This looks all fine except I would like to encapsulate the rows for each of the tables into a parent element such as:

<MyDataSet>
   <Sees>
	   <See>
		  columns...
	   </See>
   </Sees>
   <Spots>
	   <Spot>
		  columns...
	   </Spot>
   </Spots>
   <Runs>
	   <Run>
		  columns...
	   </Run>
	   <Run>
		  columns...
	   </Run>
	   <Run>
		  columns...
	   </Run>
	   <Run>
		  columns...
	   </Run>
	   <Run>
		  columns...
	   </Run>
   </Runs>
</MyDataSet>

I thought that to do so I could create a XSD (XML Schema) and apply it in to the DataSet.  How to do so though has eluded me.   I am not having any luck searching a solution on-line so I am starting to wonder if this simply won't work and I will need to write my own parser/translator.

So, here are the questions:

1.  Can I even use a XSD (XML Schema) with a DataSet under the Enterprise Library and if so how?

2.  Possibly even more important, would I even be able to get the type of output that I want if I can use a XSD file?

 

Nov 22, 2010 at 1:58 AM
Edited Nov 22, 2010 at 2:06 AM

DataSet is not really an EntLib object, so what you do with it is really outside of EntLib scope.  EntLib has also no feature that allows you to specify an xml schema for the DataSet object to use returned by ExecuteDataSet method.  If there's such feature to modify its schema, then it would have to be available in the DataSet object.  This is more of an ADO.NET question. I suggest posting this in ADO.NET forums such as this one which is specific to DataSets.

 

Sarah Urmeneta
Global Technologies & Solutions
Avanade, Inc.
entlib.support@avanade.com