XPath query C#
-
Below is the sample xml analgous to mine, "=============
...
===========" Now, I am trying write a function which says an employee with name xxx belongs to Dept xxx or not? taking two parameters,DEPT_NODE
andEMPNAME
as parameters. I can not change the signature as its from top. how to write an Xpath query for that? Thanks for anticipation. Regards. MaulikCEi don want
-
Below is the sample xml analgous to mine, "=============
...
===========" Now, I am trying write a function which says an employee with name xxx belongs to Dept xxx or not? taking two parameters,DEPT_NODE
andEMPNAME
as parameters. I can not change the signature as its from top. how to write an Xpath query for that? Thanks for anticipation. Regards. MaulikCEi don want
bool isInDepartment( string department, string employee ); XpathDocument doc= new XPathDocument(); doc.Load( ... ); XPathExpression exp = new XPathExpression( string.format("//DEPT[@name={0}]/EMP[@name={1}]", department, employee) ); return !( null == doc.SelectSingleNode( exp ) );
Or better take a look at SelectSingleNode[^]. Never forget: "Stay kul and happy" (I.A.)
David's thoughts / dnhsoftware.org / MyHTMLTidy -
bool isInDepartment( string department, string employee ); XpathDocument doc= new XPathDocument(); doc.Load( ... ); XPathExpression exp = new XPathExpression( string.format("//DEPT[@name={0}]/EMP[@name={1}]", department, employee) ); return !( null == doc.SelectSingleNode( exp ) );
Or better take a look at SelectSingleNode[^]. Never forget: "Stay kul and happy" (I.A.)
David's thoughts / dnhsoftware.org / MyHTMLTidyThanks David, My requirement is little different, I have reference to DEPT node so I have to search relatively from DEPT as other branches may also have same departments. In terms of code, bool isInDepartment( XmlElement eleDept, string employee ); What could be the XPath query for this?
-
Thanks David, My requirement is little different, I have reference to DEPT node so I have to search relatively from DEPT as other branches may also have same departments. In terms of code, bool isInDepartment( XmlElement eleDept, string employee ); What could be the XPath query for this?
If you can't work out your xpath from the help dnh gave you, then I really suggest you go and buy an xml book and read it. At the very least, run through the w3schools tutorial http://www.w3schools.com/xpath/default.asp, which will take you all of 5 minutes, rather than want someone else to write your code for you.
using System.Beer;