XPath to get a node with a certain attribute value

  • Thread starter Thread starter Guest
  • Start date Start date
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>
 
/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"]
 
Here are some more samples:
ms-help://MS.VSCC/MS.MSDNQTR.2003FEB.1033/xmlsdk/htm/xpath_syntax2_3prn.htm
 
Back
Top