当 / 位于 XML 中时,如何搜索 XML? C#?
我收到此错误代码
var ff = from files in doc.Descendants("blah/Files") select files;
The error is
The '/' character, hexadecimal value 0x2F, cannot be included in a name.
In
<File id="f8" name="/usr/include/_G_config.h"/>
现在我无法更改 XML,我需要访问其中的所有内容。我如何在 C# 中做到这一点?
I get this error with the code
var ff = from files in doc.Descendants("blah/Files") select files;
The error is
The '/' character, hexadecimal value 0x2F, cannot be included in a name.
In <Files>
there are
<File id="f8" name="/usr/include/_G_config.h"/>
Now i cant change the XML and i need to access everything in it. How do i do that in C#?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
后代 的参数必须是 XName(可以从字符串隐式转换),代表一个元素或属性名称。这些不能包含斜杠。根据完整的 XML,您可能只能使用:
或者您可能需要添加代码。
The parameter to Descendants must be an XName (which can be implicitly converted from a string), which represents an element or attribute name. These can not contain slashes. Depending on the full XML, you may just be able to use:
or you may need to add code.
您正在像尝试 XPath 一样尝试它,但它需要一个 XName,并且 XName 中不能包含“/”
相反,您可以直接执行如下操作:
You are trying it out like you would an XPath but it expects an XName and an XName cannot have a "/" in it
Instead you can directly do something like this: