Sql2XML in aspxhttp://forums.asp.net/t/1595951.aspx/1?Sql2XML+in+aspxFri, 27 Aug 2010 15:38:37 -040015959514047817http://forums.asp.net/p/1595951/4047817.aspx/1?Sql2XML+in+aspxSql2XML in aspx <p>&nbsp;To All</p> <p>&nbsp;</p> <p>I found the VB aspx script and it creates an xml and schema .. it does exactically what I want .. however .. I want the routine to just return the schema and xml and not echo anything to the screen .. just return the value or string of the schema and xml .. here is the code :</p> <p>&lt;%@ Page Language=&quot;VB&quot; %&gt;<br> &lt;%@ Import Namespace=&quot;System.Data&quot; %&gt;<br> &lt;%@ Import Namespace=&quot;System.Data.SqlClient&quot; %&gt;<br> &lt;%@ Import Namespace=&quot;System.Xml&quot; %&gt;<br> &lt;script language=&quot;VB&quot; runat=&quot;server&quot;&gt;</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;Sub Page_Load(sender as Object, e as EventArgs)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim myConnection As SqlConnection<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;Dim myCommand&nbsp;&nbsp;&nbsp; As SqlDataAdapter<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim myDataSet&nbsp;&nbsp;&nbsp; As DataSet</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ' Create connection and set connection string<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br> &nbsp;&nbsp;&nb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&quot;Password=lipkinrm&quot; )&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;' Create a new command object that uses our connection<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ' and set the text of the command to be executed<br> &nbsp;&nbsp; myCommand = New SqlDataAdapter(&quot;select vnumber,license,agency from vehicles order by vnumber;&quot;, _<br> &nbsp;&nbsp;&nbsp;myConnection)</p> <p>&nbsp;&nbsp;' Create a new dataset<br> &nbsp;&nbsp;myDataSet = New DataSet()<br> &nbsp;&nbsp;<br> &nbsp;&nbsp;' This line changes the name of the outer container<br> &nbsp;&nbsp;' tags in the resulting xml file.<br> &nbsp;&nbsp;myDataSet.DataSetName = &quot;something&quot;<br> &nbsp;&nbsp;<br> &nbsp;&nbsp;' Use the command to fill our DataSet<br> &nbsp;&nbsp;myCommand.Fill(myDataSet, &quot;vehicles&quot;)</p> <p>&nbsp;&nbsp;<br> &nbsp;&nbsp;' We've got our data... now save it to the output file:<br> &nbsp;&nbsp;<br> &nbsp;&nbsp;' File paths<br> &nbsp;&nbsp;Dim strXsdPath As String = Server.MapPath(&quot;db_xml.xsd&quot;)<br> &nbsp;&nbsp;Dim strXmlPath As String = Server.MapPath(&quot;db_xml.xml&quot;)</p> <p>&nbsp;&nbsp;' Write out schema to .xsd file and data to .xml file<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '&nbsp; myDataSet.WriteXmlSchema(strXsdPath)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '&nbsp; myDataSet.WriteXml(strXmlPath, XmlWriteMode.IgnoreSchema)<br> &nbsp;&nbsp;<br> &nbsp;&nbsp;' Could also write both schema and data to a single file<br> &nbsp;&nbsp;myDataSet.WriteXml(strXmlPath, XmlWriteMode.WriteSchema)<br> &nbsp;&nbsp;<br> &nbsp;&nbsp;' Or ignore the schema and just write data to .xml file<br> &nbsp;&nbsp;'myDataSet.WriteXml(strXmlPath)</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br> &nbsp;End Sub<br> &nbsp;<br> &lt;/script&gt;</p> <p>&lt;html&gt;<br> &lt;head&gt;<br> &lt;title&gt;ASP.NET ADO.NET to XML Sample&lt;/title&gt;<br> &lt;/head&gt;<br> &lt;body&gt;</p> <p>&lt;p&gt;<br> XML file written...<br> click &lt;a href=&quot;db_xml.xml&quot;&gt;here&lt;/a&gt; to view the .xml file.<br> &lt;/p&gt;</p> <p>&lt;p&gt;<br> XSD file written...<br> click &lt;a href=&quot;db_xml.xsd&quot;&gt;here&lt;/a&gt; to view the .xsd file.<br> &lt;/p&gt;</p> <p>&lt;/body&gt;<br> &lt;/html&gt;</p> <p>&nbsp;</p> <p>Instead or writing the file out .. how can I just return the value :</p> <p>' Could also write both schema and data to a single file<br> &nbsp;&nbsp;myDataSet.WriteXml(strXmlPath, XmlWriteMode.WriteSchema)<br> </p> <p>Thanks</p> <p>Rick Lipkin</p> <p><a href="mailto:r1.1955@live.com">r1.1955@live.com</a></p> <p>&nbsp;</p> 2010-08-26T20:57:58-04:004047896http://forums.asp.net/p/1595951/4047896.aspx/1?Re+Sql2XML+in+aspxRe: Sql2XML in aspx <p>Well you need to show us the method WriteXml and WriteXmlSchema (by the looks of it they are extension methods and will have a signature like:<br> <br> public static WriteXml(this DataSet data, blah, blah)<br> </p> 2010-08-26T22:00:11-04:004049364http://forums.asp.net/p/1595951/4049364.aspx/1?Re+Sql2XML+in+aspxRe: Sql2XML in aspx <p>WriteXml is&nbsp;part of the .net 4 framework :</p> <p><a href="http://msdn.microsoft.com/en-us/library/system.data.dataset.writexml.aspx">http://msdn.microsoft.com/en-us/library/system.data.dataset.writexml.aspx</a>&nbsp;</p> <p>WriteXML is also part of the .net 4 framework :</p> <p><a href="http://msdn.microsoft.com/en-us/library/system.data.dataset.writexmlschema.aspx">http://msdn.microsoft.com/en-us/library/system.data.dataset.writexmlschema.aspx</a></p> <p>&nbsp;</p> <p>What I am trying to do is to return a database schema and xml to an Web Ajax framework to populate a grid .. It appears that XML Webservices .. endpoints and 'soap' is going away in SQL after version 2008 .. here is the article from Microsoft :<br> &nbsp;<br> <a href="http://technet.microsoft.com/en-us/library/cc280436.aspx" target="_blank"><font color="#0066cc">http://technet.microsoft.com/en-us/library/cc280436.aspx</font></a><br> &nbsp;<br> <br> </p> &lt;div&gt;Native XML Web Services: Deprecated in SQL Server 2008&lt;/div&gt; &lt;div id=ecxmainSection&gt; &lt;div id=ecxmainBody&gt;<br> &lt;div&gt;This feature will be removed in a future version of Microsoft SQL Server. Avoid using this feature in new development work, and plan to modify applications that currently use this feature.<br> Native XML Web Services (SOAP/HTTP endpoints) is deprecated; Native XML Web Services will be removed from a future version of SQL Server.&nbsp;Plan to convert your existing SOAP/HTTP endpoints <strong>to use Windows Communications Foundation (WCF) or ASP.NET</strong>.&nbsp;Avoid using SOAP/HTTP endpoints in new development work.&lt;/div&gt; &lt;div&gt;&nbsp;&lt;/div&gt; &lt;div&gt;I am trying to come up with a way of extracting data via xml from a Sql Server for populating a web development project I am working on .. outside of VS 2010.&lt;/div&gt; &lt;div&gt;&nbsp;&lt;/div&gt; &lt;div&gt;Hope that helps explain what I am trying to acomplish.&lt;/div&gt; &lt;div&gt;&nbsp;&lt;/div&gt; &lt;div&gt;Rick Lipkin&lt;/div&gt; &lt;div&gt;<a href="mailto:r1.1955@live.com">r1.1955@live.com</a>&lt;/div&gt;&lt;/div&gt;&lt;/div&gt; 2010-08-27T15:38:37-04:00