解析XML,我需要在Java中创建一个应用程序,可以解析XML文档(我写的美元,我应该得到的回报率吧) http://www.bnr.ro/nbrfxrates.xml 我的代码现在的样子:从Java网址
package bnr;
import java.net.URL;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
public class Bnr {
/**
* @param args the command line arguments
*/
String url = "http://www.bnr.ro/nbrfxrates.xml";
public static void main(String[] args) {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(new URL(url).openStream());
}
}
和它不工作我得到一个解析错误。 你能告诉我它有什么问题吗? 谢谢
你能分享确切的错误信息?顺便说一句。此代码不会编译,因为您有未处理的异常,并且您在静态方法中使用非静态变量。 –