I am having to write a XPath Query to pull out the answer for a question based on the question id. The question id is passed dynamically to the query. I cannot use LINQ as the solution is in NET 2.0. Please find the XML file below
<?xml version="1.0" encoding="utf-8" ?>
<Questionaire>
<question id="1">
<answer>1</answer>
<correctAnswer>Text</correctAnswer>
</question>
<question id="2">
<answer>2</answer>
<correctAnswer>Text</correctAnswer>
</question>
</Questionaire>
I’am a novice to XPath and find it hard to get my head around it.
Many thanks in advance.
Your XPath expression can be dynamically generated like this:
then, depending on the object representing the XML document you need to call one of the following methods:
Select(),SelectNodes(),SelectSingleNode(),Evaluate().Read the MSDN documentation about the appropriate methods of
XmlDocument,XPathDocument,XPathNavigatorandXPathExpression.