I have an xml file
<RTT>
    <AgencyList>
        <agency Name="Bart" Ditection="Outbound">
            <RouteList>
                <Route Name="Fremont" Direction="test">
                    <Stop ID="25" Name="BayFare"/>
                </Route>
                <Route Name="SFO" Direction="Test"/>
                <Route Name="SFO" Direction="Test"/>
            </RouteList>
        </agency>
    </开发者_StackOverflowAgencyList>
</RTT>
I would like to know how to get a node list which contains all the Route which has no child nodes using C#.
E.g The Node list should contain only
<Route  Name="SFO" Direction "Test">
<Route  Name="SFO" Direction "Test">
The XPATH expression: //Route[not(node())] will address those Route elements.
It can be used in C# with something like this:
XmlDocument xml = new XmlDocument();
xml.Load("RTT.xml"); //adjust correct path/filename
XmlNodeList xnList = xml.SelectNodes("//Route[not(node())]");
foreach (XmlNode xn in xnList)
{
  //Do something with the selected elements
}
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论