selectSingleNode

I am sure that this is very easy. It's just that I am new to XML. I have spent an hour on this already (just today) and am behind deadline.

I have an XMLNode xIn.

<Column Value="PerformerName" Out="TableX.PerName"/>

I can access the attribute value via

xIn.SelectSingleNode("/Main/Tables/Table/Columns/Column/@Value")

but not with

xIn.SelectSingleNode("@Value")

Is there a way to access it relatively and not absolutely? (absolutely: having to start from the top with Main/Tables/etc.)

Also, why does

xIn.SelectSingleNode("/Main/Tables/Table/Columns/Column[@Value=PerformerName]")

Not give me the same result?
LVL 2
jj_30Asked:
Who is Participating?
 
AcumentalityCommented:
I think maybe //@Value=PerformerName or
//@Value='PerformerName'
0
 
AcumentalityCommented:
I'm not sure if this works...
xIn.SelectSingleNode("//@Value")

Open in new window

0
 
jj_30Author Commented:
Yes, that does work,

should

xIn.SelectSingleNode("//[@Value=PerformerName]")

Also work? I also tried

xIn.SelectSingleNode("//[Value=PerformerName]")
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
jj_30Author Commented:
I'm trying to loop through the nodes, like this ...

So I wanted "relative" querying ... this notation that you gave me is sort of what I want, but not really.

For instance, if I do xIn.SelectSingleNode("//@KeyRelationship"), it returns TRUE, even though it's only true for the first child node.

  for (int i = 0; i < xCols.ChildNodes.Count; i++)
            {
                //loop through the columns to build the udpate statement
                if (i > 0) {
                    sColumnList += ", ";
                    sColumnsReadList += ", ";
                }
                sColumnList += XML.GetNodeValueFromNode(xCols.ChildNodes[i], "//@Out");
                sColumnList += " = " + i.ToString() + " ";
                sColumnsReadList += XML.GetNodeValueFromNode(xCols.ChildNodes[i], "//@Value");
 
                sKeyRelationship = XML.GetNodeValueFromNode(xCols.ChildNodes[i], "//@KeyRelationship");
 
            }

Open in new window

0
 
jj_30Author Commented:
Here is part of my XML

      <Columns>
        <Column Value="ActorsName" Out="ChaName" KeyRelationship="True"/>
        <Column Value="HasMemChar" Out="MemCharacter"/>
      </Columns>

Open in new window

0
 
AcumentalityCommented:
If that doesn't work, try:
xIn.SelectSingleNode("//*[@Value=PerformerName]")

Open in new window

0
 
AcumentalityCommented:
My last answer was correct.
0
 
jj_30Author Commented:
I will try it Monday when I get back to work.
0
 
jj_30Author Commented:
//@Value='PerformerName' works fine
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.