Solved

selectSingleNode

Posted on 2009-05-08
10
1,411 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Major Incident Management Communications

Major incidents and IT service outages cost companies millions. Often the solution to minimizing damage is automated communication. Find out more in our Major Incident Management Communications infographic.

 
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
 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
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.
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

734 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