':' 字符,十六进制值 0x3A,不能包含在名称中 [英] The ':' character, hexadecimal value 0x3A, cannot be included in a name
问题描述
我有一个 xml 文件,其中包含其元素,如
I have an xml file that contains its element like
<ab:test>Str</ab:test>
当我尝试使用代码访问它时:
When I am trying to access it using the code:
XElement tempElement = doc.Descendants(XName.Get("ab:test")).FirstOrDefault();
它给了我这个错误:
System.Web.Services.Protocols.SoapException:服务器无法处理请求.---> System.Xml.XmlException: ':' 字符,十六进制值 0x3A,不能包含在名称中.
System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.Xml.XmlException: The ':' character, hexadecimal value 0x3A, cannot be included in a name.
我应该如何访问它?
推荐答案
如果您想使用命名空间,LINQ to XML 让这一切变得非常简单:
If you want to use namespaces, LINQ to XML makes that really easy:
XNamespace ab = "http://whatever-the-url-is";
XElement tempElement = doc.Descendants(ab + "test").FirstOrDefault();
在您的文档中查找 xmlns:ab=...
部分,以找出ab"指的是哪个命名空间 URI.
Look for an xmlns:ab=...
section in your document to find out which namespace URI "ab" refers to.
这篇关于':' 字符,十六进制值 0x3A,不能包含在名称中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!