简体   繁体   English

选择TreeView的所有Checked节点的XPATH表达式是什么?

[英]What would be the XPATH expression to select all Checked Nodes of a TreeView?

Here is my XML : 这是我的XML:

<Tree CheckBoxes="True" CheckChildNodes="True" TriStateCheckBoxes="True" MultipleSelect="True" EnableAjaxSkinRendering="False" BorderStyle="Inset" Height="100%"  Width="99%" RenderMode="Lightweight">
<Node Text="Consumer" Value="79" Expanded="True" Checked="True" >
  <Node Text="BASIC" Value="7983" Expanded="True" Checked="True" >
    <Node Text="RED" Value="7983BL" Checked="True" >
      <Node Text="E17" Value="906268" Checked="True"  />
      <Node Text="W57" Value="906390" />
    </Node>
    <Node Text="BLUE" Value="7983CG" >
      <Node Text="T2T" Value="906359"  />
    </Node>
    <Node Text="GREEN" Value="7983GO" >
      <Node Text="VCR" Value="906386"  />
    </Node>
    <Node Text="WHITE" Value="7983GP" Checked="True" >
      <Node Text="2B3" Value="906246" Checked="True"  />
    </Node>
  </Node>
  <Node Text="ENHANCED" Value="7984" Checked="True" >
    <Node Text="PURPLE" Value="7984CN" Checked="True" >
      <Node Text="V8Q" Value="906588" Checked="True"  />
      <Node Text="V8R" Value="906589"  />
      <Node Text="V8S" Value="906590" Checked="True"  />
    </Node>
    <Node Text="ORANGE" Value="7984CV" >
      <Node Text="3A5" Value="906408"  />
    </Node>
  </Node>
</Node>

In this XML, if any child node has attribute Checked="True" then its Parent Node would also have Checked="True". 在此XML中,如果任何子节点具有属性Checked =“ True”,则其父节点也将具有Checked =“ True”。 I wanted the XPath Expression to exclude all nodes that do not have attribute Checked="True" regardless of the Node Level. 我希望XPath表达式排除所有不具有属性Checked =“ True”的节点,而不管节点级别如何。

Thanks, Nishant 谢谢,Nishant

XDocument xml = XDocument.Load(reader);
xml.Root.DescendantsAndSelf().Where(node =>
{
  try
  {
    return node.Attribute("Checked").Value.ToString() != "True";
  }
  catch
  {
    //no attribute @Checked 
    return true;
  }
}).Remove();

Given that, i wanted to remove the nodes that did not contain the 'Checked' attribute at all, I found a much faster way : 鉴于此,我想删除根本不包含“ Checked”属性的节点,我发现了一种更快的方法:

XDocument xml = XDocument.Load(reader); XDocument xml = XDocument.Load(阅读器); xml.Root.DescendantsAndSelf().Where(node => node.Attribute("Checked") = null).Remove(); xml.Root.DescendantsAndSelf()。Where(node => node.Attribute(“ Checked”)= null).Remove();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM