• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1742
  • Last Modified:

dataset getxml/writexml

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
trevorhartman
Asked:
trevorhartman
  • 6
  • 4
  • 2
2 Solutions
 
raterusCommented:
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
 
trevorhartmanAuthor Commented:
i'm not using a typed dataset..
0
 
trevorhartmanAuthor Commented:
i'm not even sure what that is
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
laotzi2000Commented:
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
 
laotzi2000Commented:
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
 
raterusCommented:
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
 
trevorhartmanAuthor Commented:
very interesting stuff, thanks guys
0
 
trevorhartmanAuthor Commented:
well looks like i'll need to refresh my xsd..
0
 
trevorhartmanAuthor Commented:
using XSD, is there any way i can force it to write empty elements?
0
 
raterusCommented:
maybe you could set any null values to "" before you write out the xml
0
 
trevorhartmanAuthor Commented:
set them to "" by recursing through the rows of the datatable?  or is there a better way?
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 6
  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now