如何将 Java 代码从使用本地 XML 文件切换为使用 XML 文件的 URL

发布于 2024-12-26 11:52:05 字数 620 浏览 4 评论 0原文

我编写了一个 Web 应用程序,它读取 XMl 文件并对其进行解析并执行一些工作。

我不想使用本地文件,而是想使用 XML 文件的 URL(类似于 http:// /mydomain.com/daily-extract.xml

这就是我的代码的样子:

 private String xmlFile = "D:\\default-user\\WINXP\\Desktop\\extract-jan10d.xml";

 SAXBuilder builder =  new SAXBuilder("org.apache.xerces.parsers.SAXParser");
 // Parse the specified file and convert it to a JDOM document
 document = builder.build(new File(xmlFile));

 Element root = document.getRootElement();

How can I switch from a file to a URL on the internet

I have written web application that reads an XMl file parses it and does some work.

Rather than using a local file, I'd like to use a URL of the XML file ( something like http://mydomain.com/daily-extract.xml )

This is what my code looks like:

 private String xmlFile = "D:\\default-user\\WINXP\\Desktop\\extract-jan10d.xml";

 SAXBuilder builder =  new SAXBuilder("org.apache.xerces.parsers.SAXParser");
 // Parse the specified file and convert it to a JDOM document
 document = builder.build(new File(xmlFile));

 Element root = document.getRootElement();

How can I switch from a file to a URL on the internet

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

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

发布评论

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

评论(1

我三岁 2025-01-02 11:52:05

尝试替换这一行:

document = builder.build(new File(xmlFile));

通过:

document = builder.build(new File(new URI("http://mydomain.com/daily-extract.xml")));

Try to replace this line :

document = builder.build(new File(xmlFile));

By :

document = builder.build(new File(new URI("http://mydomain.com/daily-extract.xml")));

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