SelectNodes Query

R

Rama

I am trying to use selectnodes on parentNode of the context Node and it is
not returning the correct resull. Heres my XML

1 <a>
2 <fields>
3 <field name='test1' >
4 <b>
5 <a>
6 <fields> // This is parent Node
7 <field name='test1' > // Context Node
8 </fields>
9 </a>
10 </b>
11 <field name='test2' >
12 </fields>
13 </a>

My Context node is node corresponding to line 7. The following code returns
2 nodes instead of 1 , nodes corresponding to line 3 and line 7
CurrentNode.parentNode.selectNodes("//fields/field[@name='test1']")

What is it that I am missing ? Any help would be appreciated.

Thanks,

Rama
 
S

Steve van Dongen [MSFT]

I am trying to use selectnodes on parentNode of the context Node and it is
not returning the correct resull. Heres my XML

1 <a>
2 <fields>
3 <field name='test1' >
4 <b>
5 <a>
6 <fields> // This is parent Node
7 <field name='test1' > // Context Node
8 </fields>
9 </a>
10 </b>
11 <field name='test2' >
12 </fields>
13 </a>

My Context node is node corresponding to line 7. The following code returns
2 nodes instead of 1 , nodes corresponding to line 3 and line 7
CurrentNode.parentNode.selectNodes("//fields/field[@name='test1']")

What is it that I am missing ? Any help would be appreciated.

It is returning the correct result. Perhaps you should tell us which
node(s) you wanted it to return.

Regards,
Steve
 
R

Rama

Steve,
Since my context node is <field name='test1' > , I am trying to go one
step back to the parent node; the xml corresponding to the parent nopde
should be as follows :
<fields>
<field name='test1' > // my context node
<field name= 'test11'>
<field name ='test1'2 >
</fields>

My objective is to find out if attribute 'name' for nodes 'field' is
unique within its parent node 'fields'. My Xml DOM also contain 'field' node
at some other levels and it is somehow returning every node named field
within the document.
I hope, i have made my problem clear, let me know if i further need to
clarify anything.

Thanks,

Rama

Steve van Dongen said:
I am trying to use selectnodes on parentNode of the context Node and it is
not returning the correct resull. Heres my XML

1 <a>
2 <fields>
3 <field name='test1' >
4 <b>
5 <a>
6 <fields> // This is parent Node
7 <field name='test1' > // Context Node
8 </fields>
9 </a>
10 </b>
11 <field name='test2' >
12 </fields>
13 </a>

My Context node is node corresponding to line 7. The following code returns
2 nodes instead of 1 , nodes corresponding to line 3 and line 7
CurrentNode.parentNode.selectNodes("//fields/field[@name='test1']")

What is it that I am missing ? Any help would be appreciated.

It is returning the correct result. Perhaps you should tell us which
node(s) you wanted it to return.

Regards,
Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top