That is the correct XPath expression, but the result you get depends on how you evaluate it. The XPath expression /accounts/account/name
returns a node set containing (in document order) all the name
child elements of all the account
elements under the accounts
root element in the document.
In the XPath data model the string value of a node set is defined to be the string value of the first node in the set. So if you use the single-argument evaluate
:
fax.evaluate(someDocument)
this will evaluate the expression as a string and you'll just get the first name
value. Instead you need to evaluate the expression as a node set, then extract the string value of each node in turn, as suggested in koopajah's answer.