<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://forums.asp.net/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>XML and XmlDataSource Control</title><link>http://forums.asp.net/43.aspx</link><description>All about XML, XSLT, and the XmlDataSource control.</description><dc:language>en</dc:language><generator>CommunityServer 2007 SP1 (Build: 20510.895)</generator><item><title>Re: dataset.WriteXML</title><link>http://forums.asp.net/thread/3273158.aspx</link><pubDate>Fri, 03 Jul 2009 09:24:04 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3273158</guid><dc:creator>pavipinnamaneni</dc:creator><author>pavipinnamaneni</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3273158.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=43&amp;PostID=3273158</wfw:commentRss><description>&lt;p&gt;Thanks &lt;b&gt;benhobgood,&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp; Thanks for the help, i have been search on this from the past few days.&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/p&gt;</description></item><item><title>Re: dataset.WriteXML</title><link>http://forums.asp.net/thread/2679906.aspx</link><pubDate>Mon, 13 Oct 2008 18:30:31 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:2679906</guid><dc:creator>benhobgood</dc:creator><author>benhobgood</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/2679906.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=43&amp;PostID=2679906</wfw:commentRss><description>&lt;p&gt;This post is very old but for what it is worth I would have liked to find this solution out there when I was searching so here it is:&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I had a similar problem where I created a disk cache solution using datasets, I wrote the files using DataSet.WriteXML(filePath)&amp;nbsp;and read them back in via DataSet.ReadXML(filePath).&amp;nbsp; Exceptions were thrown if I tried to access a column from the dataset that was null. To get around this problem simply include the Schema when you read and write so that when you access the data the dataset object understands that the column exists but contains no data.&lt;/p&gt;
&lt;p&gt;There are 2 ways of doing this depending upon your approach:&lt;br /&gt;1) If you are using the same output for each call it is probably more &lt;span style="FONT-SIZE:11pt;FONT-FAMILY:&amp;#39;Calibri&amp;#39;,&amp;#39;sans-serif&amp;#39;;mso-ascii-theme-font:minor-latin;mso-fareast-font-family:Calibri;mso-fareast-theme-font:minor-latin;mso-hansi-theme-font:minor-latin;mso-bidi-font-family:&amp;#39;Times New Roman&amp;#39;;mso-bidi-theme-font:minor-bidi;mso-ansi-language:EN-US;mso-fareast-language:EN-US;mso-bidi-language:AR-SA;"&gt;efficient &lt;/span&gt;to reuse schemas:&lt;/p&gt;
&lt;p&gt;MyDataSet.WriteXML(file)&lt;br /&gt;MyDataSet.WriteXMLSchema(fileUniqueToOutputStructure)&lt;br /&gt;&lt;br /&gt;MyDataSet.ReadXMLSchema(fileUniqueToOutputStructure)&lt;br /&gt;MyDataSet.ReadXML(file)&lt;br /&gt;&lt;br /&gt;2) Or, with a little more overhead but easier to manage and write - just write the XML schema into each dataset output:&lt;br /&gt;&lt;br /&gt;DataSet.&lt;font size="2"&gt;WriteXml(file, XmlWriteMode.WriteSchema)&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;DataSet.&lt;font size="2"&gt;ReadXml(file, XmlReadMode.ReadSchema)&lt;/p&gt;&lt;/font&gt;</description></item><item><title>Re: dataset.WriteXML</title><link>http://forums.asp.net/thread/1090792.aspx</link><pubDate>Sat, 22 Oct 2005 12:12:55 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:1090792</guid><dc:creator>rmprimo</dc:creator><author>rmprimo</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/1090792.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=43&amp;PostID=1090792</wfw:commentRss><description>&lt;FONT size=2&gt;Something else I thought of.&lt;BR&gt;&lt;BR&gt;You can leave all the columns as elements(default) but mark BOTH the Table and the columns as nillable.&lt;BR&gt;&lt;/FONT&gt;&lt;BR&gt;&lt;FONT color=#0000ff size=2&gt;
&lt;P&gt;&lt;FONT size=1&gt;&amp;lt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=1&gt;&lt;FONT color=#800000&gt;xs:element&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; &lt;/FONT&gt;&lt;FONT color=#ff0000&gt;name&lt;/FONT&gt;&lt;FONT color=#0000ff&gt;=&lt;/FONT&gt;"&lt;FONT color=#0000ff&gt;DataTable1&lt;/FONT&gt;"&lt;FONT color=#0000ff&gt;&amp;nbsp;&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; &lt;/FONT&gt;&lt;FONT color=#ff0000&gt;nillable&lt;/FONT&gt;&lt;FONT color=#0000ff&gt;=&lt;/FONT&gt;"&lt;FONT color=#0000ff&gt;true&lt;/FONT&gt;"&lt;/FONT&gt;&lt;FONT size=1&gt;&lt;FONT color=#0000ff&gt;&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;&lt;/FONT&gt;&lt;FONT color=#800000&gt;xs:complexType&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=1&gt;&lt;FONT color=#0000ff&gt;&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;&lt;/FONT&gt;&lt;FONT color=#800000&gt;xs:sequence&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=1&gt;&lt;FONT color=#0000ff&gt;&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;&lt;/FONT&gt;&lt;FONT color=#800000&gt;xs:element&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; &lt;/FONT&gt;&lt;FONT color=#ff0000&gt;name&lt;/FONT&gt;&lt;FONT color=#0000ff&gt;=&lt;/FONT&gt;"&lt;FONT color=#0000ff&gt;Column1&lt;/FONT&gt;"&lt;FONT color=#0000ff&gt; &lt;/FONT&gt;&lt;FONT color=#ff0000&gt;type&lt;/FONT&gt;&lt;FONT color=#0000ff&gt;=&lt;/FONT&gt;"&lt;FONT color=#0000ff&gt;xs:string&lt;/FONT&gt;"&lt;FONT color=#0000ff&gt; &lt;/FONT&gt;&lt;FONT color=#ff0000&gt;minOccurs&lt;/FONT&gt;&lt;FONT color=#0000ff&gt;=&lt;/FONT&gt;"&lt;FONT color=#0000ff&gt;0&lt;/FONT&gt;"&lt;FONT color=#0000ff&gt; &lt;/FONT&gt;&lt;FONT color=#ff0000&gt;nillable&lt;/FONT&gt;&lt;FONT color=#0000ff&gt;=&lt;/FONT&gt;"&lt;FONT color=#0000ff&gt;true&lt;/FONT&gt;"&lt;/FONT&gt;&lt;FONT size=1&gt;&lt;FONT color=#0000ff&gt; /&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;&lt;/FONT&gt;&lt;FONT color=#800000&gt;xs:element&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; &lt;/FONT&gt;&lt;FONT color=#ff0000&gt;name&lt;/FONT&gt;&lt;FONT color=#0000ff&gt;=&lt;/FONT&gt;"&lt;FONT color=#0000ff&gt;Column2&lt;/FONT&gt;"&lt;FONT color=#0000ff&gt; &lt;/FONT&gt;&lt;FONT color=#ff0000&gt;type&lt;/FONT&gt;&lt;FONT color=#0000ff&gt;=&lt;/FONT&gt;"&lt;FONT color=#0000ff&gt;xs:string&lt;/FONT&gt;"&lt;FONT color=#0000ff&gt; &lt;/FONT&gt;&lt;FONT color=#ff0000&gt;minOccurs&lt;/FONT&gt;&lt;FONT color=#0000ff&gt;=&lt;/FONT&gt;"&lt;FONT color=#0000ff&gt;0&lt;/FONT&gt;"&lt;/FONT&gt;&lt;FONT size=1&gt;&lt;FONT color=#0000ff&gt; &lt;FONT color=#ff0000&gt;nillable&lt;/FONT&gt;&lt;FONT color=#0000ff&gt;=&lt;/FONT&gt;"&lt;FONT color=#0000ff&gt;true&lt;/FONT&gt;"&lt;FONT color=#0000ff&gt; &lt;/FONT&gt;/&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/&lt;/FONT&gt;&lt;FONT color=#800000&gt;xs:sequence&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=1&gt;&lt;FONT color=#0000ff&gt;&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/&lt;/FONT&gt;&lt;FONT color=#800000&gt;xs:complexType&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=1&gt;&lt;FONT color=#0000ff&gt;&amp;gt;&lt;BR&gt;&amp;lt;/&lt;/FONT&gt;&lt;FONT color=#800000&gt;xs:element&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&amp;gt;&lt;/P&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;BR&gt;&lt;FONT size=2&gt;Then you will end up getting &lt;FONT color=#ff0000&gt;xsi:nil&lt;/FONT&gt;&lt;FONT color=#0000ff&gt;=&lt;/FONT&gt;"&lt;FONT color=#0000ff&gt;true&lt;/FONT&gt;" attribute in&amp;nbsp;tags of the empty&amp;nbsp;elements in the instance&lt;FONT color=#0000ff&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;FONT color=#000000&gt;DataSet Xml&lt;BR&gt;&lt;/FONT&gt;&lt;BR&gt;It is even bindable.&lt;BR&gt;&lt;/FONT&gt;&lt;BR&gt;&lt;A href="http://msdn2.microsoft.com/en-us/library/ybce7f69"&gt;&lt;FONT size=2&gt;http://msdn2.microsoft.com/en-us/library/ybce7f69&lt;/FONT&gt;&lt;BR&gt;&lt;/A&gt;&lt;BR&gt;HTH!</description></item><item><title>Re: dataset.WriteXML</title><link>http://forums.asp.net/thread/1090537.aspx</link><pubDate>Fri, 21 Oct 2005 23:40:23 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:1090537</guid><dc:creator>rmprimo</dc:creator><author>rmprimo</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/1090537.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=43&amp;PostID=1090537</wfw:commentRss><description>&lt;P&gt;&lt;FONT size=1&gt;&lt;FONT color=#0000ff size=2&gt;&lt;/P&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;Using XmlDocument totally bypasses the DataSet which is&amp;nbsp;a much richer&amp;nbsp;API. &lt;BR&gt;&lt;BR&gt;The only reason&amp;nbsp;you may need this is&amp;nbsp;human readability, otherwise it is just extra markup, and if networked, extra traffic. An xml editor like XmlSpy &lt;A href="http://www.altova.com/download_spy_enterprise.html"&gt;http://www.altova.com/download_spy_enterprise.html&lt;/A&gt;&amp;nbsp;or the Xml Data Editor in the IDE&amp;nbsp;show the data tabulated&amp;nbsp;&lt;STRONG&gt;&lt;EM&gt;with the nulls&lt;/EM&gt;&lt;/STRONG&gt;.&lt;BR&gt;&lt;BR&gt;If you do use XmlDocument you might want to use one of the overloads that&amp;nbsp;formats your output.&lt;BR&gt;You can do a little hack to see the empty rows.&lt;BR&gt;&lt;BR&gt;
&lt;P&gt;&lt;FONT size=1&gt;&amp;lt;&lt;/FONT&gt;&lt;FONT color=#800000 size=1&gt;TestDataSet&lt;/FONT&gt;&lt;FONT size=1&gt;&lt;FONT color=#0000ff&gt;&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;&lt;/FONT&gt;&lt;FONT color=#800000&gt;DataTable1&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; &lt;/FONT&gt;&lt;FONT color=#ff0000&gt;AttColumn1&lt;/FONT&gt;&lt;FONT color=#0000ff&gt;=&lt;/FONT&gt;"&lt;FONT color=#0000ff&gt;Value 1&lt;/FONT&gt;"&lt;FONT color=#0000ff&gt; &lt;/FONT&gt;&lt;FONT color=#ff0000&gt;AttColumn2&lt;/FONT&gt;&lt;FONT color=#0000ff&gt;=&lt;/FONT&gt;"&lt;FONT color=#0000ff&gt;Value 2&lt;/FONT&gt;"&lt;/FONT&gt;&lt;FONT color=#0000ff size=1&gt; /&amp;gt;&lt;BR&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff&gt;&lt;FONT size=1&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;&lt;FONT color=#800000&gt;DataTable1 /&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff&gt;&lt;FONT size=1&gt;&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;&lt;FONT color=#800000&gt;DataTable1 /&lt;/FONT&gt;&lt;FONT color=#0000ff&gt;&lt;FONT size=1&gt;&amp;gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;BR&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=1&gt;&lt;FONT color=#0000ff&gt;&amp;lt;/&lt;/FONT&gt;&lt;FONT color=#800000&gt;TestDataSet&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&amp;gt;&lt;BR&gt;&lt;/P&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;BR&gt;&lt;BR&gt;1. The schema element for DataTable must not be unique.&lt;BR&gt;2. Convert the column elements to attributes in the schema. The IDE by default sets them as elements.&lt;BR&gt;3. watch out for PKs, which wouldn't give you empty rows anyway.&lt;BR&gt;4. If you are already doing it in the db, you might want to loosen up validation for the columns &lt;FONT size=1&gt;&lt;FONT color=#ff0000&gt;msprop:nullValue&lt;/FONT&gt;&lt;FONT color=#0000ff&gt;=&lt;/FONT&gt;"&lt;FONT color=#0000ff&gt;_throw&lt;/FONT&gt;"|"&lt;FONT color=#0000ff&gt;_empty&lt;/FONT&gt;"|"&lt;FONT color=#0000ff&gt;_null&lt;/FONT&gt;"&lt;BR&gt;&lt;/FONT&gt;&lt;BR&gt;HTH!&lt;BR&gt;&lt;/FONT&gt;
&lt;P&gt;&lt;FONT color=#0000ff size=2&gt;&lt;/P&gt;&lt;/FONT&gt;
&lt;P&gt;&lt;FONT size=1&gt;&lt;FONT color=#0000ff size=2&gt;&amp;nbsp;&lt;/P&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;BR&gt;&lt;BR&gt;&lt;BR&gt;&lt;BR&gt;&lt;BR&gt;&lt;BR&gt;</description></item><item><title>Re: dataset.WriteXML</title><link>http://forums.asp.net/thread/1089226.aspx</link><pubDate>Thu, 20 Oct 2005 18:24:53 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:1089226</guid><dc:creator>jcw14</dc:creator><author>jcw14</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/1089226.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=43&amp;PostID=1089226</wfw:commentRss><description>I'm afraid you'll have to write code, the WriteXML method suppresses the null columns by design.&lt;BR&gt;&lt;BR&gt;So you might do something like this:&lt;BR&gt;&lt;BR&gt;&lt;FONT size=2&gt;
&lt;P&gt;XmlDocument xml = WriteDataTable(ds.Tables[0]);&lt;BR&gt;xml.Save("XML File Path");&lt;/FONT&gt;&amp;nbsp;&lt;FONT size=2&gt;&lt;/P&gt;
&lt;P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;XmlDocument WriteDataTable(DataTable table) &lt;BR&gt;{&lt;BR&gt;&amp;nbsp; XmlDocument xml = &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;new&lt;/FONT&gt;&lt;FONT size=2&gt; XmlDocument();&lt;BR&gt;&amp;nbsp; xml.LoadXml("&amp;lt;Table/&amp;gt;");&lt;BR&gt;&amp;nbsp; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;foreach&lt;/FONT&gt;&lt;FONT size=2&gt; ( DataRow dr &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;in&lt;/FONT&gt;&lt;FONT size=2&gt; table.Rows) &lt;BR&gt;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; XmlElement xmlRow = xml.CreateElement(table.TableName);&lt;BR&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; foreach&lt;/FONT&gt;&lt;FONT size=2&gt; (DataColumn col &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;in&lt;/FONT&gt;&lt;FONT size=2&gt; table.Columns) &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; XmlElement xmlCol = xml.CreateElement(col.ColumnName);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; xmlCol.InnerText = dr[col].ToString();&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; xmlRow.AppendChild(xmlCol);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;&amp;nbsp; xml.AppendChild(xmlRow);&lt;BR&gt;&amp;nbsp; }&lt;BR&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&amp;nbsp; return&lt;/FONT&gt;&lt;FONT size=2&gt; xml;&lt;BR&gt;}&lt;BR&gt;&lt;BR&gt;&lt;BR&gt;&lt;/P&gt;&lt;/FONT&gt;</description></item><item><title>dataset.WriteXML</title><link>http://forums.asp.net/thread/1089119.aspx</link><pubDate>Thu, 20 Oct 2005 16:21:15 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:1089119</guid><dc:creator>jcheriat</dc:creator><author>jcheriat</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/1089119.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=43&amp;PostID=1089119</wfw:commentRss><description>Setup:&lt;br&gt;
I have a dataset that holds data that was retrieved from a
database.&amp;nbsp; Some of the data in the dataset is null (for some, null
for the whole column).&amp;nbsp; Upon successful retrieval of data, I want
to write the data to an XML file.&lt;br&gt;
&lt;br&gt;
Problem:&lt;br&gt;
When I use the dataset.WriteXML(filename) method, it successfully
writes the data to the xml file, BUT the columns that have null values
throughout get left out of the final output (if there is a field that
has a null value then it will not be represented in that record in the
xml file).&lt;br&gt;
&lt;br&gt;
Question:&lt;br&gt;
Is there any way I can force the writing of the entire dataset (All
columns being represented regardless if an entire column is null)?&lt;br&gt;
&lt;br&gt;
Thanks in advance for your help.&lt;br&gt;
&lt;br&gt;
&lt;br&gt;</description></item></channel></rss>