Hexadecimal value 0x00 is a invalid character

后端 未结 6 1740
悲&欢浪女
悲&欢浪女 2020-12-17 08:06

I am generating an XML document from a StringBuilder, basically something like:

string.Format(\"{0}{1}         


        
6条回答
  •  無奈伤痛
    2020-12-17 08:26

    I'm using IronPython here (same as .NET API) and reading the file as UTF-8 in order to properly handle the BOM fixed the problem for me:

    xmlFile = Path.Combine(directory_str, 'file.xml')
    doc = XPathDocument(XmlTextReader(StreamReader(xmlFile.ToString(), Encoding.UTF8)))
    

    It would work as well with the XmlDocument:

    doc = XmlDocument()
    doc.Load(XmlTextReader(StreamReader(xmlFile.ToString(), Encoding.UTF8)))
    

提交回复
热议问题