I have a program that generates Xml files from data from a database. In short code, he does the following:
string dsn = "a db connection string"; XmlDocument d = new XmlDocument(); using (SqlConnection con = new SqlConnection(dsn)) { con.Open(); string sql = "select id as Id, comment as Comment from Test where ... "; using (SqlCommand cmd = new SqlCommand(sql, con)) { DataSet ds = new DataSet("EXPORT"); SqlDataAdapter da = new SqlDataAdapter(cmd); da.Fill(ds, "Test"); d.LoadXml(ds.GetXml()); } } d.Save(@"c:\test.xml");
When I look at the xml file, it contains an invalid character and # x 1 A;
<EXPORT> <Test> <Id>2</Id> <Comment> Keyboard NB5 linked</Comment> </Test> </EXPORT>
This xml file cannot be opened by firefox browser with invalid character ...
This object is reserved in ISO 8859-1 and CP1252 and should not be displayed by browsers. But why does the XmlDocument output xml that cannot be parsed as valid - or is it a valid XML document that simply cannot be parsed by browsers or imported by Excel and so on ... Is there an easy way to get rid of these reserved โinvalid charactersโ or to encode them in such a way that browsers have no problem with it?
Thanks so much for your feedback and tips.
source share