Trouble extracting the correct XmlNode using XPath and C#

I am trying to use XPath and C# to extract the second label with the name "searchbox-search-results-button"

<?xml version="1.0" encoding="utf-8"?>
<content-item>
  <createDate>
    11/23/2011
  </createDate>
  <lastModified>
    12/12/2011
  </lastModified>
  <displayTitle>
    Options
  </displayTitle>
  <author>
    me
  </author>

  <labels>
    <label name="TEST-LABEL-FOR-UNIT-TEST">
      <![CDATA[TEST LABEL FOR UNIT TEST
]]>
    </label>
    <label name="searchbox-search-results-button">
      <![CDATA[Search Results
]]>
    </label>
  </labels>
</content-item>


I am using the following but only getting all the labels, not the specifc one I want to get.

var searchStr = //content-item/labels[label/@name='searchbox-search-results-button']
var xmlDoc = new XmlDocument();
xmlDoc.Load(DataPath + xmlFile);
return xmlDoc.SelectSingleNode(searchStr);

How do I use XPath to find a single node???
newbiewebSr. Software EngineerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sybeCommented:
//content-item/labels[label/@name='searchbox-search-results-button']

should be

/content-item/labels[label/@name='searchbox-search-results-button']


0
sybeCommented:
sorry:

/content-item/labels/label[@name='searchbox-search-results-button']
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
newbiewebSr. Software EngineerAuthor Commented:
Thanks. But the InnerText property has the text for all lable, not the single one associated with 'searchbox-search-results-button'. I don't get it.
0
Amazon Web Services

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

newbiewebSr. Software EngineerAuthor Commented:
Thanks!
0
newbiewebSr. Software EngineerAuthor Commented:
That is still not right. I re-arranged the sequence of the XML:

<?xml version="1.0" encoding="utf-8"?>
<content-item>
  <createDate>
    11/23/2011
  </createDate>
  <lastModified>
    12/12/2011
  </lastModified>
  <displayTitle>
    Options
  </displayTitle>
  <author>
    me
  </author>

  <labels>
    <label name="searchbox-search-results-button">
      <![CDATA[Search Results
]]>
      <label name="TEST-LABEL-FOR-UNIT-TEST">
      <![CDATA[TEST LABEL FOR UNIT TEST
]]>
    </label>
    </label>
  </labels>
</content-item>


And the InnerText contained the CDATA for both labels. I want just the one requested. Do you know how to fix this?
0
newbiewebSr. Software EngineerAuthor Commented:
Sorrry, i used bad XML. It seems to work fine. Thanks.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
XML

From novice to tech pro — start learning today.