How to create XPath query expression on two nodes?

I have an input xml like:

<Event>
 <DataResults>
    <DataAnalysis>
    <sID>5</sID>
     <cID>3</cID>
     <Result/>
     <Result/>
      ...
  </DataAnalysis>
 </DataResults>
  </AnalysisResults>
</Event>

I need a only the XmlNodeList of all Result nodes depending on the two nodes cID and sID and
I have try a query like this:

 string match = string.Format("/DataResults/DataAnalysis[cID = '{0}' and sID = '{1}']", CID,SID);
 XmlNodeList results = doc.DocumentElement.SelectNodes(match);

What is wrong with that?
This is under Compact Framework ...
koleto115Asked:
Who is Participating?

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

x
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.

openshacCommented:
Try
 string match = string.Format("Event/DataResults/DataAnalysis[cID = '{0}' and sID = '{1}']", CID,SID);

or

 string match = string.Format("//DataResults/DataAnalysis[cID = '{0}' and sID = '{1}']", CID,SID);
koleto115Author Commented:
No luck!
Both solutions are not working.
The second one throws exception ...

I try both of them with:
 doc.DocumentElement.SelectNodes(match);
I will remove now the DocumentElement from the call
openshacCommented:
I did notice that the xml your provided was invalid:

You don't open the element <AnalysisResults> you only close it.

I think maybe you need

XmlNodeList results = doc.SelectNodes(match);
JavaScript Best Practices

Save hours in development time and avoid common mistakes by learning the best practices to use for JavaScript.

koleto115Author Commented:
Sorry It is just example xml and a made meistake on it AnalysisResults =is actually DataResults.
I modify the real names of the xml nodes.

The problem is still there after I removed the DocumentElement and did the query directly on the doc both of the solution are throwing exception.

:-(
openshacCommented:
The following works for me:
XmlDocument doc = new XmlDocument();
 
doc.LoadXml("<Event><DataResults><DataAnalysis><sID>5</sID><cID>3</cID></DataAnalysis>" 
            + "<DataAnalysis><sID>5</sID><cID>4</cID></DataAnalysis>"
            + "<DataAnalysis><sID>5</sID><cID>3</cID></DataAnalysis>"
            + "</DataResults></Event>");
 
int CID = 3;
int SID = 5;
 
XmlNodeList nodes = doc.SelectNodes(string.Format("Event/DataResults/DataAnalysis[cID = '{0}' and sID = '{1}']", CID,SID));
Console.Write(nodes.Count);  //Returns 2

Open in new window

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
koleto115Author Commented:
It is very strange it works with the sample code but not with the real  xml.
I think the problem is not on the XPath query ...

Anyway I have to look on the original xml
Thanks!
openshacCommented:
Do you want to post the actual XML?
koleto115Author Commented:
No, I cannot! But I found the mistake :-)
I load a wrong file that does not contains any of these nodes ... How can I be so stupid!!!
;-)
I think I will try to become somehow rich and will stop working ...
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
Microsoft Development

From novice to tech pro — start learning today.