Quantcast
Channel: .NET Framework Class Libraries forum
Viewing all articles
Browse latest Browse all 8156

how to print Empty tag in Xml using C#.net

$
0
0

I'm creating a program using C#  that makes an XML file.

It uses dataset for writing, but there's one thing I'm not sure how to do.

I want the output like this...<Name> </Name>

But now its getting like this...<Name/>

Here is my Code

private void btnXML_Click(object sender, RoutedEventArgs e)
        {
            DataSet ds = CreateDynamicDataSet();
            ds.WriteXml(@"C:\Test\xmlfile.xml");           
     
        }
        private DataSet CreateDynamicDataSet()
        {

            DataSet ds = new DataSet("DS");
            ds.Namespace = "StdNamespace";
            DataTable stdTable = new DataTable("Student");
            DataColumn col1 = new DataColumn("Name");
            DataColumn col2 = new DataColumn("Address");
            stdTable.Columns.Add(col1);
            stdTable.Columns.Add(col2);
            ds.Tables.Add(stdTable);

            //Add student Data to the table
            DataRow newRow; newRow = stdTable.NewRow();
            newRow["Name"] = "Nila";
            newRow["Address"] = "Meadowlake Dr, Dtown";
            stdTable.Rows.Add(newRow);
            newRow = stdTable.NewRow();

            newRow["Name"] = "";
            newRow["Address"] = "NewYork";
            stdTable.Rows.Add(newRow);
            newRow = stdTable.NewRow();
            newRow["Name"] = "Mike Gold";
            newRow["Address"] = "New York";

            stdTable.Rows.Add(newRow);

            ds.AcceptChanges();

            return ds;

      }    
<?xml version="1.0" standalone="yes"?>
-<DS xmlns="StdNamespace">
-<Student>
 <Name>Nila</Name>
 <Address>Meadowlake Dr, Dtown</Address>
 </Student>
-<Student>
 <Name/>....................................I want like this <Name> </Name>
 <Address>NewYork</Address>
 </Student>
-<Student>
 <Name>Mike Gold</Name>
 <Address>New York</Address>
 </Student>
 </DS>


Viewing all articles
Browse latest Browse all 8156

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>