I am new to xpath in C # and I am trying to select an element that has two specific values. This XML format looks like
<?xml version="1.0" encoding="utf-8"?>
<Manager>
<SSH>
<Tunnels>
<Port>
<Local>443</Local>
<Remote>443</Remote>
</Port>
<Port>
<Local>5432</Local>
<Remote>5432</Remote>
</Port>
<Port>
<Local>19</Local>
<Remote>21</Remote>
</Port>
<Port>
<Local>19</Local>
<Remote>22</Remote>
</Port>
</Tunnels>
</SSH>
</Manager>
I tried to select "Port" which had values from the previous form, so I can remove this particular entry from xml. This was the code I used:
XmlNode _xmlTunnel = _xml.SelectSingleNode("/Manager/SSH/Tunnels/Port[Local=" + _local + "] | /Manager/SSH/Tunnels/Port[Remote=" + _remote + "]");
MessageBox.Show("Local " + sshList.SelectedItems[0].Text + " Remote " + sshList.SelectedItems[0].SubItems[1].Text +"\n\n" + _xmlTunnel.InnerText);
_xmlTunnel.RemoveAll();
XmlNodeList emptyElements = _xml.SelectNodes(@"//*[not(node())]");
for (int i = emptyElements.Count -1; i >= 0; i--) {
emptyElements[ i ].ParentNode.RemoveChild(emptyElements[ i ]); }
, . , (.. Local = 19 Remote = 21, node, Local = 19 Remote = 22). xpath '' '|' SelectSingleNode, " node -set". , , "".
, ? , xpath/xml #, , . , Windows .net 4.0, .