如何从XElement中获取所有非空节点?
我正在尝试从实际具有值的 XElement 中获取所有节点, 目前我正在使用此代码:
var nodes = from node in elem.Nodes()
where node.NodeType == XmlNodeType.Element &&
((XElement) node).Value.Length > 0
select node;
是否有内置运算符可以执行此操作?
谢谢
I'm trying to get all nodes from an XElement that actually has a value,
currently I'm using this code:
var nodes = from node in elem.Nodes()
where node.NodeType == XmlNodeType.Element &&
((XElement) node).Value.Length > 0
select node;
Is there a build in operator to do this operation?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不相信有这样的内置东西。您确定要包含具有子元素的元素吗?例如:
这将打印:
... 因此
Foo
将作为“空”节点包含在内,即使它包含另一个元素。这绝对是你所追求的吗?I don't believe there's anything like this built in. Are you sure you want to include elements that have subelements though? For example:
This will print:
... so
Foo
would be included as an "empty" node even though it contains another element. Is that definitely what you're after?