C# Dataset WriteXml generate xml file but there column name getting changed

T.Zacks 3,986 Reputation points

I am looking for help to understand what logic is behind column name in xml file which is generated by DataSet WriteXml() function.

Here is small program which generate xml file by DataSet WriteXml()

List<string> prd = new List<string>();
            prd.Add("2010 FYA");
            prd.Add("2011 FYA");
            prd.Add("2012 FYA");
            prd.Add("2013 FYA");
            prd.Add("1Q 2014A");
            prd.Add("2Q 2014A");
            prd.Add("3Q 2014A");
            prd.Add("4Q 2014A");
            prd.Add("2014 FYA");

            DataSet dsQcViewall = new DataSet();
            DataTable dtQcViewAllSave = new DataTable();

            DataColumn dcSection = new DataColumn();
            dcSection.ColumnName = "Section ";
            dcSection.DataType = Type.GetType("System.String");

            DataColumn dcLi = new DataColumn();
            dcLi.ColumnName = "LineItem";
            dcLi.DataType = Type.GetType("System.String");

            DataColumn dcReviseDate = new DataColumn();
            dcReviseDate.ColumnName = "Revise Date";
            dcReviseDate.DataType = Type.GetType("System.String");


            for (int i = 0; i <= prd.Count-1; i++)
                DataColumn dcperiod = new DataColumn();
                dcperiod.ColumnName = prd[i];
                dcperiod = null;

            DataRow dr= dtQcViewAllSave.NewRow();
            dr["Section "] = "MS";
            dr["LineItem"] = "Morgan Stanley";
            dr["Revise Date"] = "10-09-2020";

            for (int i = 0; i <= prd.Count - 1; i++)
                dr[prd[i]] = 1200;

The xml file got generated and from there i got this xml code. please have a look.

<?xml version="1.0" standalone="yes"?>
    <LineItem>Morgan Stanley</LineItem>

1) see this column Section_x0020_
actual column name was Section then why WriteXML function append x0020 after Section

2) see this one <_x0032_010_x0020_FYA>1200</_x0032_010_x0020_FYA>

i have a column 2010 FYA why WriteXml() change it to _x0032_010_x0020_FYA ?

what is logic begin after x0032 and 010 and x0020_

how do i recognize that which column is 2010 FYA ?

which logic WriteXML is using to append x0032 and 010 and x0020_ ?

please help me to understand the column naming convention. thanks

An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,199 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Timon Yang-MSFT 9,571 Reputation points

    According to the naming rules of Xml, the element name cannot start with a number, and the element name cannot contain spaces.

    Consider using camel case nomenclature or adding underscores to rename your elements.

    Names of Declared XML Elements and Attributes (Visual Basic)

    XML Naming Rules

    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments