Click here to Skip to main content
15,894,825 members

How to display null values in xml using dataset

Obopeng asked:

Open original thread
I'm having an issue relating a xml document, i want to show null values ( they dont show up on xml structure ) as an empty string or something,

Example:

XML
<?xml version="1.0" standalone="yes"?>
<SerialisedData>
  <xs:schema id="SerialisedData" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:msprop="urn:schemas-microsoft-com:xml-msprop">
    <xs:element name="SerialisedData" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
      <xs:complexType>
        <xs:choice minOccurs="0" maxOccurs="unbounded">
          <xs:element name="Table1" msprop:BaseTable.0="TABLE_NAME" msprop:BaseSchema="SCHEMA_NAME">
            <xs:complexType>
              <xs:sequence>
                <xs:element name="FILE" msprop:OraDbType="126" msprop:BaseColumn="FILE" type="xs:string" minOccurs="0" />
                <xs:element name="BBid" msprop:OraDbType="113" msprop:BaseColumn="BBid" type="xs:long" minOccurs="0" />
                <xs:element name="trnid" msprop:OraDbType="113" msprop:BaseColumn="trnid" type="xs:long" minOccurs="0" />
                <xs:element name="stnid" msprop:OraDbType="113" msprop:BaseColumn="stnid" type="xs:long" minOccurs="0" />
                <xs:element name="PIGGYBACK" msprop:OraDbType="126" msprop:BaseColumn="PIGGYBACK" type="xs:string" minOccurs="0" />
                <xs:element name="PAY_TYPE" msprop:OraDbType="126" msprop:BaseColumn="PAY_TYPE" type="xs:string" minOccurs="0" />
                <xs:element name="AMT" msprop:OraDbType="107" msprop:BaseColumn="AMT" type="xs:decimal" minOccurs="0" />
                <xs:element name="POSNUMBER" msprop:OraDbType="126" msprop:BaseColumn="POSNUMBER" type="xs:string" minOccurs="0" />
              </xs:sequence>
            </xs:complexType>
          </xs:element>
        </xs:choice>
      </xs:complexType>
    </xs:element>
  </xs:schema>

<Table1>
  <BBid>503101</BBid>
    <trnid>1377982613101</trnid>
    <stnid>13100</stnid>
    <PAY_TYPE>01</PAY_TYPE>
    <AMT>10000</AMT>
    <POSNUMBER>CCT001</POSNUMBER>
  </Table1>
  <Table1>
  <BBid>573101</BBid>
    <trnid>1377982723101</trnid>
    <stnid>13100</stnid>
    <PAY_TYPE>01</PAY_TYPE>
    <AMT>1000</AMT>
    <POSNUMBER>CCT001</POSNUMBER>
  </Table1>

I want to display like this (including the PIGGYBACK column):

<Table1>
 <BBid>573101</BBid>
    <trnid>1377982763101</trnid>
    <stnid>13100</stnid>
    <PAY_TYPE>01</PAY_TYPE>
    <AMT>9000</AMT>
    <POSNUMBER>CCT001</POSNUMBER>
    <PIGGYBACK></PIGGYBACK>
  </Table1>

<Table1>
 <BBid>573101</BBid>
    <trnid>1377982763101</trnid>
    <stnid>13100</stnid>
    <PAY_TYPE>01</PAY_TYPE>
    <AMT>9000</AMT>
    <POSNUMBER>CCT001</POSNUMBER>
    <PIGGYBACK></PIGGYBACK>
  </Table1>


My PIGGYBACK column contains/returns null from the view/table (DataSet) and I am referencing this column in my code further down.

I use the following to Write the XML file:

ASM
DataSet ds = new DataSet("SerialisedData");
        ds.WriteXml(@"C:\FileName.XML", XmlWriteMode.WriteSchema);



To Read the file:

ASM
DataSet ds = new DataSet("SerialisedData");
            ds.ReadXml(@"C:\FileName.XML", XmlReadMode.ReadSchema);



How can I do this?

Thank you in advance for your help.

Thanks!
Tags: C# 3.5

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900