"'The ':' 字符,十六进制值 0x3A,不能包含在名称中" ,加载 xml 文件时 usinf XDocument

"'The ':' character, hexadecimal value 0x3A, cannot be included in a name" , when loading xml file usinf XDocument

我必须读取一个 XML 文件,但它在第一个文件中有“:” node.I 当我尝试使用 XDocument 或 XElement 或 xmldocument.I不知道如何解决这个问题。

string _filePath= @"C:\testfile.xml";
XDocument xDoc = XDocument.Load(_filePath);

"The ':' character, hexadecimal value 0x3A, cannot be included in a name. Line 1, position 6".

我的XML文档:

<?xml:stylesheet type="text/xsl" href="\10.189.41.02\g$\XMLTest-Viewer.xsl"?>
<TestXml>
//More data here
 </TestXml>

如果我手动删除冒号,我可以成功加载文件,有没有一种方法可以在不更改 XML 文件的情况下使用“:”加载文件?

正确的 processing-instruction 名称是 xml-stylesheet,而不是 xml:stylesheet。 well-formed XML 中不允许处理指令名称中的冒号 - 或者换句话说,您正在尝试读取不是 XML.

的文件