Click here to Skip to main content
14,978,864 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi All,

I know this issue has been asked many times and I resolved this issue by implementing the solution provided from one of the blog but I am still facing the issue.

Here I am converting a datatable to xml where i can expect mobile no column can be empty and need to handle exception properly during conversion.
Below is the code snippet



C#
ublic string convertGridDataToXML()
        {
            StringBuilder stb = new StringBuilder();
           DataTable dt = (DataTable) Session["Datatable"];
           // DataTable dt = (DataTable)GridView.DataSource;
            try
            {
                if (dt!=null)
                {
                    stb.Append("<employees>");
                    foreach (DataRow row in dt.Rows)
                    {
                        stb.Append("<names>");
                        stb.Append(string.Format("<staffid> {0} </staffid>", row[0].ToString()));
                        stb.Append(string.Format("<firstname> {0} </firstname>", row[1].ToString()));
                        stb.Append(string.Format("<lastname> {0} </lastname>", row[2].ToString()));
                        stb.Append(string.Format("<mobileno> {0} </mobileno>", (row[3].ToString() == " " ? " " : row[3].ToString())));
                        stb.Append(string.Format("<cardno> {0} </cardno>", row[4].ToString()));
                        stb.Append(string.Format("<email> {0} </email>", row[5].ToString()));
                        stb.Append("</names>");

                    }
                    stb.Append("</employees>");
                }
                else
                {
                    stb.Append("<employees></employees>");
                }
            }


}'


When I am submitting this to the database I am getting this error "Reference to undeclared entity 'nbsp'. Line 1, position 155" . Can some one provide help in getting the effective solution for handling this exception.
Posted
Updated 17-Feb-15 17:33pm
v2

XML does not understand nbsp. You can define it in your xml page where you add it to your DOCTYPE element:
XML
<!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#160;"> ]>

now you can use &nbsp; in your xml page!
or you can just use the number everywhere, which is less readable: &#160;
   
v2
Comments
Prashant Bangaluru 19-Feb-15 23:19pm
   
I am not saving the file in xml.. I am feeling that I have to do some encoding and decoding which I am missing.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




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