XPath to get a node with a certain attribute value

G

Guest

I'm having trouble understanding XPath syntax
string pth = "/Settings/Puzzle/something where name is equal to Alpha"

node = doc.SelectSingleNode(pth)

Obviously I want the <Puzzle> node whose name attribute is "Alpha" but I do not know how to express that with XPath syntax. How do I do that? (xml file is below)

Thanks,
Jo

<?xml version="1.0" encoding="utf-8" ?><Settings><Current>Alpha</Current><Puzzle name="Alpha"><Divisor>786</Divisor><Quotient>4579</Quotient><Dividend>3599094</Dividend></Puzzle><Puzzle name="Beta"><Divisor>867</Divisor><Quotient>5479</Quotient><Dividend>4750293</Dividend></Puzzle><Puzzle name="Gamma"><Divisor>793</Divisor><Quotient>6842</Quotient><Dividend>5425706</Dividend></Puzzle></Settings>
 
K

Kristofer Andersson

/Settings/Puzzle[@name="Alpha"]

Jon said:
Obviously I want the <Puzzle> node whose name attribute is "Alpha" but I
do not know how to express that with XPath syntax. How do I do that? (xml
file is below).

/Settings/Puzzle[@name="Alpha"]
 
K

Kristofer Andersson

Here are some more samples:
ms-help://MS.VSCC/MS.MSDNQTR.2003FEB.1033/xmlsdk/htm/xpath_syntax2_3prn.htm
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

using XPath 2

Top