调用 Xdocument.save 之前应跳过的字符
我有这个问题..我正在从客户端接收数据..使用套接字连接。但这并不重要。所有数据都使用 XDocument 对象存储在 XML 文件中。 有时,当调用 XDocument.Save(filestream) 并向其传递带有特定字符或符号的数据时,我会收到类似(无效的十六进制字符)的异常,这意味着 XML 文件不能包含某些特殊字符? 如果是这样,我在哪里可以找到可以生成此类异常的特殊字符的列表?
I have this problem.. I'm receiving data from a client..Using a socket connection. But this is not important. All the data is stored in an XML file using the XDocument object.
Sometimes when calling the XDocument.Save(filestream) and passing to it data with particular characters or symbols, I get an Exception like (invalid Hexadecimal character), it means that the XML file could not have some special characters ?
If so where can I find a list of this special characters that could generate such Exceptions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
[0x0-0x1F] 范围内的字符称为控制字符,除了 0x9、0xA、0xD 之外,它们不能在 XML 中使用。
以下是 XML 规范 的引用:
Characters in the range [0x0-0x1F] are called control characters and excluding 0x9, 0xA, 0xD they cannot be used in XML.
Here's a quote from the XML specification:
@Darin 给出的答案应该能让你指出正确的方向。我要补充的是,如果您有 xml 开发工具,例如 XMLSpy 或 Stylus Studio 您可以快速确定有问题的字符。如果您没有这样的工具,您可以使用 WC3 学校提供的在线 xml 验证器:
http ://www.w3schools.com/xml/xml_validator.asp
这将检查 xml 的格式是否正确,如果包含无效字符,则格式不正确。
更不可能的情况可能是 xml 文档指定的编码确实允许导致问题的字符。如果文档被指定为 UTF-8(很可能就是这样),那么这不太可能是问题所在。
The answer given by @Darin should get you pointed in the right direction. I will add that if you have a tool for xml development such as XMLSpy or Stylus Studio you can quickly determine the offending characters. If you don't have such a tool you can use the online xml validator from WC3 schools found here:
http://www.w3schools.com/xml/xml_validator.asp
This will check that the xml is well formed and if it contains invalid characters it will not be well formed.
A more unlikely scenario might be that the encoding specified by the xml document does allow the characters causing the problem. If the document is specified as UTF-8, which it probably is, then this is not likely the problem.