开发者

XMLTextWriter To WiterData Using C#.Net Application

开发者 https://www.devze.com 2023-01-23 02:57 出处:网络
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,

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

精彩评论

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