Solved

selectSingleNode

Posted on 2009-05-08
10
1,404 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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

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.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

758 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

18 Experts available now in Live!

Get 1:1 Help Now