将Xpath从java转换为c# [英] Converting Xpath from java to c#

查看:111
本文介绍了将Xpath从java转换为c#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿伙计们,我需要你的帮助。

1.我不确定这段代码是什么

2.我怎么重写这个是c#,因为c#库中不存在XpathApi。

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.

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

推荐答案

通过使用 XmlDocument 类在.NET中支持XPath表达式。



你可以从这里开始:

XPath语法 [ ^ ]

XmlDocument类 [ ^ ]



希望这会有所帮助。



添加了XmlNode的例子



正如我在评论中所说, SelectSingleNode 方法也存在于 XmlNode 类。



java代码的粗略翻译可能是:

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

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

Hope this helps.

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:
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;
   }
}





(粗略因为我不经常使用XML文档;但我希望你有这个想法)



[/ EDIT]



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

[/EDIT]


这篇关于将Xpath从java转换为c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆