zoukankan      html  css  js  c++  java
  • XmlWriter.WriteString() problem__“.”(十六进制值 0x00)是无效的字符。


    Tom Delany wrote:
    > According to the Microsoft documentation, the .NET class
    > System.Xml.XmlWriter.WriteString() does the following:
    >
    > "Character values in the range 0x-0x1F (excluding white space characters
    > 0x9, 0xA, and 0xD) are replaced with numeric character entities (�
    > through &#0x1F)."
    >
    > However, when we call WriteString() in an application we have written, we
    > are seeing the following exception being thrown:
    >
    > System.ArgumentException: '', hexadecimal value 0x12, is an invalid
    > character.
    > at System.Xml.XmlUtf8RawTextWriter.InvalidXmlChar(Int32 ch, Byte*
    > pDst, Boolean entitize)
    > at System.Xml.XmlUtf8RawTextWriter.WriteElementTextBlock(Char* pSrc,
    > Char* pSrcEnd)
    > at System.Xml.XmlUtf8RawTextWriter.WriteString(String text)
    > at System.Xml.XmlUtf8RawTextWriterIndent.WriteString(String text)
    > at System.Xml.XmlWellFormedWriter.WriteString(String text)
    >
    > Anyone ever seen anything like this? Any idea what I am doing wrong?


    XmlTextWriter in the .NET framework 1.0/1.1 did that and XmlTextWriter
    in the .NET framework 2.0 still does that but the normal XmlWriter you
    create with e.g. XmlWriter.Create has been fixed to be compliant with
    the XML 1.0 specification and to ensure (by default) that the output is
    well-formed and even escaping those characters is not allowed in the XML
    1.0 specification.
    So use new XmlTextWriter to create an XmlTextWriter or if you want to
    use XmlWriter.Create, then use XmlWriterSettings with CheckCharacters
    set to false e.g.

    XmlWriterSettings writerSettings = new XmlWriterSettings();
    writerSettings.CheckCharacters = false;
    using (XmlWriter xmlWriter = XmlWriter.Create("file.xml",
    writerSettings))
    {
    // ...
    }
    writerSettings.CheckCharacters = false;设置为false将不检查字符 就不会出现“.”(十六进制值 0x00)是无效的字符。类似的情况了,哇咔咔
  • 相关阅读:
    像素与豪米的转换
    C#中的事件和委托
    .Datagridview数据写入DataTable
    C# winform DataGridView 常见属性
    c# winform 用代码修改DataGridView列头的名字,设置列名,修改列名
    SVN常用命令
    (装载)C#中AppDomain.CurrentDomain.BaseDirectory与Application.StartupPath的区别
    C# WinForm dataGridView 技巧小结
    IPV4二进制显示
    Microsoft SQL Server 2005技术内幕:TSQL查询 PerformanceDB.sql
  • 原文地址:https://www.cnblogs.com/crazycxy/p/2507403.html
Copyright © 2011-2022 走看看