C# 中的 SAXParser 等效项

发布于 2024-09-26 18:24:13 字数 1344 浏览 0 评论 0原文

我有下面的java代码,我需要将它们转换为C#,请帮助我..

public class Configuration {

  private ConfigContentHandler confHandler;

  public Configuration() {
  }

  public boolean parseConfigFile() throws Exception {
    boolean bReturn = true;

    SAXParser parser = SAXParserFactory.newInstance().newSAXParser();

    System.out.println("*** Start parsing");

    try {
       confHandler = new ConfigContentHandler(100);
       // Configuration file must be located in main jar file folder

       // Set the full Prosper file name
       String sConfigFile = "configuration.xml";

       // Get abstract (system independent) filename
       File fFile = new File(sConfigFile);

       if (!fFile.exists()) {
          System.out.println("Could not find configuration file " + sConfigFile + ", trying input parameters.");
          bReturn = false;
       }  else if (!fFile.canRead()) {
          System.out.println("Could not read configuration file " + sConfigFile + ", trying input parameters.");
          bReturn = false;
       } else {
          parser.parse(fFile, confHandler);
       }

    } catch (ArrayIndexOutOfBoundsException e) {
        System.out.println("Input error.");
    } catch (Exception e) {
        e.printStackTrace();
    }

    System.out.println("*** End parsing");
    return bReturn;
  }

谢谢

I have below java code , I need to convert these in C#, Kindly help me ..

public class Configuration {

  private ConfigContentHandler confHandler;

  public Configuration() {
  }

  public boolean parseConfigFile() throws Exception {
    boolean bReturn = true;

    SAXParser parser = SAXParserFactory.newInstance().newSAXParser();

    System.out.println("*** Start parsing");

    try {
       confHandler = new ConfigContentHandler(100);
       // Configuration file must be located in main jar file folder

       // Set the full Prosper file name
       String sConfigFile = "configuration.xml";

       // Get abstract (system independent) filename
       File fFile = new File(sConfigFile);

       if (!fFile.exists()) {
          System.out.println("Could not find configuration file " + sConfigFile + ", trying input parameters.");
          bReturn = false;
       }  else if (!fFile.canRead()) {
          System.out.println("Could not read configuration file " + sConfigFile + ", trying input parameters.");
          bReturn = false;
       } else {
          parser.parse(fFile, confHandler);
       }

    } catch (ArrayIndexOutOfBoundsException e) {
        System.out.println("Input error.");
    } catch (Exception e) {
        e.printStackTrace();
    }

    System.out.println("*** End parsing");
    return bReturn;
  }

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

∞梦里开花 2024-10-03 18:24:13

C# 本机 XML 解析器 XmlReader 不支持 SAX 和是只向前的。您可以查看这篇文章 提出一些具体观点。您可以使用 XmlReader 模拟 SAX 解析器。如果它不适合您的需求,您也可以使用 XDocument 这是一个不同的 API,用于在 .NET 中处理 XML 文件。因此,总而言之,.NET 框架中没有内置推送 XML 解析器,因此如果您确实需要事件驱动的解析器,则可能需要使用第三方库或 COM Interop to MSXML 来实现此目的。

C# native XML parser XmlReader doesn't support SAX and is forward-only. You may take a look at this article presenting some specific points about it. You could simulate a SAX parser using XmlReader. If it doesn't suit your needs you could also use XDocument which is a different API for working with XML files in .NET. So to conclude there's no push XML parser built into .NET framework so you might need to use a third party library or COM Interop to MSXML to achieve this if you really need an event driven parser.

差↓一点笑了 2024-10-03 18:24:13

我过去在两个项目中成功使用了 SAX for .NET。
http://saxdotnet.sourceforge.net/

I used SAX for .NET in two projects successfully in the past.
http://saxdotnet.sourceforge.net/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文