Solved

selectSingleNode

Posted on 2009-05-08
10
1,405 Views
Last Modified: 2013-11-11
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?
0
Comment
Question by:jj_30
  • 5
  • 4
10 Comments
 
LVL 1

Expert Comment

by:Acumentality
ID: 24336067
I'm not sure if this works...
xIn.SelectSingleNode("//@Value")

Open in new window

0
 
LVL 2

Author Comment

by:jj_30
ID: 24336149
Yes, that does work,

should

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

Also work? I also tried

xIn.SelectSingleNode("//[Value=PerformerName]")
0
 
LVL 2

Author Comment

by:jj_30
ID: 24336286
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
 
LVL 2

Author Comment

by:jj_30
ID: 24336295
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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 1

Accepted Solution

by:
Acumentality earned 125 total points
ID: 24336316
I think maybe //@Value=PerformerName or
//@Value='PerformerName'
0
 
LVL 1

Expert Comment

by:Acumentality
ID: 24336589
If that doesn't work, try:
xIn.SelectSingleNode("//*[@Value=PerformerName]")

Open in new window

0
 
LVL 1

Expert Comment

by:Acumentality
ID: 24338796
My last answer was correct.
0
 
LVL 2

Author Comment

by:jj_30
ID: 24344882
I will try it Monday when I get back to work.
0
 
LVL 2

Author Closing Comment

by:jj_30
ID: 31579440
//@Value='PerformerName' works fine
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Events in static methods 3 50
Need to pass connection string through config 2 26
SQL XML ALL Nodes Compare in function 2 18
Windows Media Player 2 14
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now