如何将 Java 代码从使用本地 XML 文件切换为使用 XML 文件的 URL
我编写了一个 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试替换这一行:
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")));