Solved

selectSingleNode

Posted on 2009-05-08
10
1,410 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
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

 
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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying 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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

726 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