Dataset.GetXML() RRS feed

  • Question

  • I call the dataset.getxml() method and notice that if the field is null it is excluded from the XML string.  What needs to be done to get the field to show up in the resultset regardless of whether or not it is null?


    As a workaround I am currently converting nulls to " " which fixes the issue. I am looking for a better solution, if one exists.

    Tuesday, November 20, 2007 1:21 AM

All replies

  • What do you expect a null to be represented in XML to look like? Let's say "fieldX" is the field in question, and it's a string, whose value is null. XML can output it as an element, like:



    or as an attribute, like:

    <MyObject someOtherField="Hey, I'm not null" fieldX="" anotherField="123" />


    If it outputs fieldX, how do you distinguish between an empty string value and a null? That's probably why it omits it, because then you know.


    Otherwise, think about how you think it should represent null. Like this? <fieldX>null</fieldX> or fieldX="null" ? That wouldn't fly either, because the literal value could be "null" (note the quotes), not the null value.

    Tuesday, November 20, 2007 11:06 PM
  • I am passing the data returned back to BizTalk.  If the field is omitted from the resultset because it is null then it creates issues in BizTalk.  As a workaround I could convert the null column to an empty string prior to exporting it to XML.  But that seems like a workaround rather than an elegant solution.

    Wednesday, November 21, 2007 2:16 AM
  • Hi,

    After you call GetXML you could also call a 2nd method that adds any missing tags to the xml stream.  Still clunky but less ugly.

    Sunday, December 2, 2007 6:57 PM
  • Sure sounds like the problem is that BizTalk doesn't know that the field is nullable.  Which suggests that there's a design error somewhere that needs to be fixed.


    If you're getting your DataSet out of a database, you might consider fixing the problem in the database, e.g. instead of selecting Foo, select ISNULL(Foo, '') AS Foo.

    Monday, December 3, 2007 8:36 PM