?
Solved

dataset getxml/writexml

Posted on 2005-03-11
12
Medium Priority
?
1,709 Views
Last Modified: 2010-11-30
Hi,

I have a dataset and need to return it as XML.  I can do this using GetXml or WriteXml, but both of those do not include null columns.  How can I make my null columns show up as empty elements?

Thanks - Trevor
0
Comment
Question by:trevorhartman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
  • 2
12 Comments
 
LVL 33

Expert Comment

by:raterus
ID: 13521136
Check the bottom of this article, this is a guess, but I'm fairly confident it will work.  If you use a typed dataset, and set the nullvalue to an empty string I believe it will export properly.
0
 
LVL 8

Author Comment

by:trevorhartman
ID: 13521153
i'm not using a typed dataset..
0
 
LVL 8

Author Comment

by:trevorhartman
ID: 13521154
i'm not even sure what that is
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 12

Accepted Solution

by:
laotzi2000 earned 1400 total points
ID: 13521190
You need to keep schema in this case. This is expected result. When dataSet
saves data into the XML file it ignores NULL values and does not save them.
If your column in a datatable does not have value in at least one row, then
basically the whole column will be missing in a saved XML. Then, later on
when you open saved XML, DataSet will not find this column and you could be
in a trouble. Saving Schema together with the XML data, will make you sure
that everything is OK
0
 
LVL 12

Expert Comment

by:laotzi2000
ID: 13521204
SqlDataAdapter da = new SqlDataAdapter(
     "select * from authors",
     "server=localhost;uid=sa;database=pubs");
DataSet ds = new DataSet();

da.Fill(ds, "authors");
ds.WriteXmlSchema("myauthors.xsd");
0
 
LVL 33

Expert Comment

by:raterus
ID: 13521227
ahh, and then you use ReadXMLSchema if you ever load the DataSet from xml, and the dataset will know that missing elements are null, cool
0
 
LVL 33

Assisted Solution

by:raterus
raterus earned 600 total points
ID: 13521243
0
 
LVL 8

Author Comment

by:trevorhartman
ID: 13521631
very interesting stuff, thanks guys
0
 
LVL 8

Author Comment

by:trevorhartman
ID: 13521660
well looks like i'll need to refresh my xsd..
0
 
LVL 8

Author Comment

by:trevorhartman
ID: 13522098
using XSD, is there any way i can force it to write empty elements?
0
 
LVL 33

Expert Comment

by:raterus
ID: 13522226
maybe you could set any null values to "" before you write out the xml
0
 
LVL 8

Author Comment

by:trevorhartman
ID: 13532143
set them to "" by recursing through the rows of the datatable?  or is there a better way?
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses
Course of the Month12 days, 17 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question