Click here to Skip to main content
15,908,775 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hey guys pls I need your help.
1. I am not really sure what this piece of code does
2. how do I rewrite this is c#, since XpathApi does not exist in the c# library.
Java
Node objRecorNode;
Node objCurrentField = null;


public boolean setToFirstRecord() {
  try {
       objCurrentField = XPathAPI.selectSingleNode(objRecordNode,"./FIELD");
       if(objCurrentField==null)
       return false;
    else
       return true;
      } catch(Exception e) {
      System.out.println("Error in setToFirstRecord of RecordObject "  + e.getMessage());
       return false;
    }

}

thanks for the help, very greatful
Posted
Updated 19-Sep-13 10:05am
v2

1 solution

XPath expressions are supported in .NET through the use of XmlDocument class.

You could start here:
XPath Syntax[^]
XmlDocument Class[^]

Hope this helps.

[EDIT] Added example with XmlNode

As I say in my comment, the SelectSingleNode method also exists for XmlNode class.

A (rough) translation of the java code could be:
C#
XmlNode objRecordNode;
XmlNode objCurrentField;

public bool SetToFirstRecord()
{
   try {
      objCurrentField = objRecordNode.SelectSingleNode("./FIELD");
      return (objCurrentField != null);
   }
   catch (Exception ex) {
      Debug.WriteLine(string.Format("Error in setToFirstRecord of RecordObject {0}", e.Message()));
      return false;
   }
}


(rough because I do not use XML documents so often ; but I hope you got the idea)

[/EDIT]
 
Share this answer
 
v4
Comments
rudolph098 19-Sep-13 17:01pm    
Thank for the help, actually I have been to this site already. The major thing that throws me off in the java code is that an instance of node (objRecord) is being passed as a parameter in selectSingleNode funcion, while the c# version of this function, implements it in a very different way. In C#, they performs a query on a xml document, but this java version performs a query on an object
phil.o 19-Sep-13 17:11pm    
Not exactly ; SelectSingleNode method also exists for XmlNode elements. See my updated answer.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900