Solved

selectSingleNode

Posted on 2009-05-08
10
1,412 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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Create a Windows 10 custom Image with custom task bar and custom start menu using XML for deployment.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Suggested Courses

628 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