How to select a value of an attribute with XPath?

I have xml like this one:

<DetectorData CollectionID='1'/>

whit XSLT one can get the string value like this:

<xsl:value-of select="DetectorData/@CollectionID"/>

How to get the string value with XPath and c# with similar construction?

node.SelectSingleNode("DetectorData/@CollectionID") .... does this works?
Who is Participating?

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

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.

TimCotteeHead of Software ServicesCommented:
Hello koleto115,


Should do it.


koleto115Author Commented:
Yes, but is there a simple construction that returns string.Empty?
I don't want to check whether the attribute is there or not...
The dotted notation is very ugly, I hopped that there is a kind of XPath trick to retrieve the attribute value with a single method ...
somthing like node.SelectSingleNode("DetectorData/@CollectionID" ..... something that like that ...
TimCotteeHead of Software ServicesCommented:

Not as far as I am aware, there are methods to select specific nodes based on attribute values but I don't believe that you can use it to return the value of an attribute that way.


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
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
Web Languages and Standards

From novice to tech pro — start learning today.