我有一个包含其元素的 xml 文件,如
<ab:test>Str</ab:test>
当我尝试使用代码访问它时:
XElement tempElement = doc.Descendants(XName.Get("ab:test")).FirstOrDefault();
它给我这个错误:
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 可以让这变得非常简单:
XNamespace ab = "http://whatever-the-url-is";
XElement tempElement = doc.Descendants(ab + "test").FirstOrDefault();
在文档中查找 xmlns:ab=...
部分,找出“ab”所指的命名空间 URI。
关于c# - ':'字符,十六进制值0x3A,不能包含在名称中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2575546/