开发者

XMLTextWriter To WiterData Using C#.Net Application

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜