【发布时间】:2012-07-04 19:15:30
【问题描述】:
好的,我正在通过这样做将文件缓存在内存中
byte[] file = System.IO.File.ReadAllBytes("test.xml");
然后我尝试从该缓冲区创建一个 xml 文档,如下所示:
System.IO.MemoryStream stream = new System.IO.MemoryStream(file);
System.Xml.XmlTextReader reader = new System.Xml.XmlTextReader(stream);
System.Xml.Linq.XDocument xPartDocument = new System.Xml.Linq.XDocument(reader);
但这无法创建文档并出现以下异常:
A first chance exception of type 'System.ArgumentException' occurred in System.Xml.Linq.dll Additional information: Non white space characters cannot be added to content.
然而,'reader' 看起来是错误的,即在本地人中它的值是 'None':
- 阅读器 {无} System.Xml.XmlTextReader
“文件”字节数组变量也有 11 个字节的标题(我猜这只是 txt 文件标题?):
0x0393B148 58 35 59 71 X5Yq
0x0393B14C dc 67 01 00 Üg..
0x0393B150 ef bb bf 3c <
0x0393B154 3f 78 6d 6c ?xml
0x0393B158 20 76 65 72 ver
非常感谢任何帮助。
谢谢
【问题讨论】:
-
这在我看来不像 XML 文件。
-
如果你切断了标题,它会起作用吗?不是来自sql server吗? @Blindy 它是一个 xml 文件,它只是在开头有一些 gobledygook
-
实际上这看起来像一个十六进制编辑器屏幕转储。您可以在右侧列中看到 XML 标记的开头,尽管地址有点神秘。
-
前 8 个字节是标题,从外观上看,接下来的 3 个字节是 UTF-8 BOM。你是从哪里得到这个文件的?
-
@the_ajp:我不可能不假思索地告诉你它是什么——但当我看到它时我就知道了。