xml SelectSingleNode not working as expected

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Ok I am confused as how SelectSingleNode is working. Given the following code:
<div style="background-color:white; color:black
<pre><span style="color:orangered $xml <span style="color:gray = @
<a<span style="color:gray >
<aa id<span style="color:gray =<span style="color:#a31515 "0"<span style="color:gray >
<ab id<span style="color:gray =<span style="color:#a31515 "0"<span style="color:gray >
<ac<span style="color:gray >a<<span style="color:gray /ac<span style="color:gray >
<<span style="color:gray /ab<span style="color:gray >
<<span style="color:gray /aa<span style="color:gray >
<aa id<span style="color:gray =<span style="color:#a31515 "1"<span style="color:gray >
<ab id<span style="color:gray =<span style="color:#a31515 "1"<span style="color:gray >
<ac<span style="color:gray >2<<span style="color:gray /ac<span style="color:gray >
<<span style="color:gray /ab<span style="color:gray >
<<span style="color:gray /aa<span style="color:gray >
<<span style="color:gray /a<span style="color:gray >
@


<span style="color:orangered $aa <span style="color:gray = <span style="color:#a31515 "aa"
<span style="color:orangered $ab <span style="color:gray = <span style="color:#a31515 "ab"
<span style="color:orangered $ac <span style="color:gray = <span style="color:#a31515 "ac"

<span style="color:gray [<span style="color:teal System.Reflection.Assembly<span style="color:gray ]<span style="color:gray ::LoadWithPartialName(<span style="color:#a31515 "System.Xml.Linq") | Out<span style="color:gray -Null
<span style="color:orangered $xmlDoc <span style="color:gray = New<span style="color:gray -Object Xml.XmlDocument
<span style="color:orangered $xmlDoc.LoadXml(<span style="color:orangered $xml)
<span style="color:orangered $xmlNav <span style="color:gray = <span style="color:orangered $xmlDoc.CreateNavigator()

<span style="color:orangered $aa_node <span style="color:gray = <span style="color:orangered $xmlNav.SelectSingleNode(<span style="color:#a31515 "//"<span style="color:gray +<span style="color:orangered $aa)
<span style="color:orangered $found <span style="color:gray = 0
<span style="color:blue foreach (<span style="color:orangered $ab_node <span style="color:blue in <span style="color:orangered $aa_node.Select(<span style="color:#a31515 "//"<span style="color:gray +<span style="color:orangered $ab)) {
<span style="color:#a31515 "== LOOP =="
<span style="color:orangered $ab_node
<span style="color:blue if (<span style="color:orangered $ab_node.GetAttribute(<span style="color:#a31515 "id", <span style="color:#a31515 "") <span style="color:gray -eq <span style="color:#a31515 "1") {
<span style="color:#a31515 "----"
<span style="color:orangered $ab_node.SelectSingleNode(<span style="color:#a31515 "//"<span style="color:gray +<span style="color:orangered $ac)
<span style="color:blue if (<span style="color:orangered $aa_node.SelectSingleNode(<span style="color:#a31515 "//"<span style="color:gray +<span style="color:orangered $ac).InnerXml <span style="color:gray -ne <span style="color:#a31515 "2") {
<span style="color:orangered $found <span style="color:gray = 1
<span style="color:#a31515 "FOUND!!"
}
<span style="color:orangered $drive <span style="color:gray = <span style="color:orangered $aa_node
}
}

[/code]

I expect that it does not display "FOUND!!". This is because, I expect that $ab_node.SelectSingleNode("//"+$ac).InnerXml would be 2 since it was applied to the ab node whos id attribute is 1. Why is it going to the ab node whos id attribute
is 0?
Thanks,

A
p.s. is there a way of getting the ISE to use a tab instead of 4 spaces?
<
Adrian

View the full article
 
Back
Top