We have thousand of Data To Write In XML File & To Write Data We use XmlTextWriter.
We can across one problem while Writing XML File,
Error Is While Writing Attribute : Invalid high surrogate character (0xDC50). A high surrogate character must have a value from range (0xD800 - 0xDBFF).
As A Error Solution : We decided to Replace Problematic Data With Space..
But XMLTextWriter Wan't Allow To Write Anything After WriterState is In Error. (it Says : Token StartAttribute in state Error would result in an invalid XML document.)
Here is sample Code To Relicate Error:
XmlTextWriter writer = new XmlTextWriter("C:\employees.xml", Encoding.UTF8); writer.WriteStartDocument(); writer.WriteStartElement("Employees");
try
{
string data = "뿿�� ";
writer.WriteAttributeString("Company", data);
}
catch (Exception ex)
{
//Here I Got Error For surrogate character
writer.WriteAttributeString("Company", "");//Trying To Write Again
开发者_开发技巧 }
Is there any way To write Attribute value ones it get in State Of Error?
Thanks.
Check your data string before adding it to the writer or use a CDATA block using : http://msdn.microsoft.com/en-us/library/system.xml.xmltextwriter.writecdata.aspx
精彩评论