当前位置: 技术问答>java相关
关于java中解析XML问题
来源: 互联网 发布时间:2015-05-23
本文导语: package untitled2; import javax.swing.JComponent; import org.w3c.dom.Document; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; /** * Title: * Description: * Copyright: Copyright (c) 2002 * Company: * @author *...
package untitled2;
import javax.swing.JComponent;
import org.w3c.dom.Document;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
/**
* Title:
* Description:
* Copyright: Copyright (c) 2002
* Company:
* @author
* @version 1.0
*/
public class Untitled1 extends JComponent {
public Untitled1() {
}
public void readXML(String uri){
String ordersFile = "sonnet.xml";
//Create the Document object
Document ordersDoc = null;
try {
//Create the DocumentBuilderFactory
DocumentBuilderFactory dbfactory = DocumentBuilderFactory.newInstance();
//Create the DocumentBuilder
DocumentBuilder docbuilder = dbfactory.newDocumentBuilder();
//Parse the file to create the Document
//ordersDoc=docbuilder.parse(uri);
} catch (Exception e) {
System.out.println("Problem creating document: "+e.getMessage());
}
}
public static void main(String[] argv) {
Untitled1 untitled11 = new Untitled1();
untitled11.readXML(argv[0]);
}
}
这是我的程序,但运行报错:
Problem creating document: no protocol: sonnet.xml
不知何故,请教
import javax.swing.JComponent;
import org.w3c.dom.Document;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
/**
* Title:
* Description:
* Copyright: Copyright (c) 2002
* Company:
* @author
* @version 1.0
*/
public class Untitled1 extends JComponent {
public Untitled1() {
}
public void readXML(String uri){
String ordersFile = "sonnet.xml";
//Create the Document object
Document ordersDoc = null;
try {
//Create the DocumentBuilderFactory
DocumentBuilderFactory dbfactory = DocumentBuilderFactory.newInstance();
//Create the DocumentBuilder
DocumentBuilder docbuilder = dbfactory.newDocumentBuilder();
//Parse the file to create the Document
//ordersDoc=docbuilder.parse(uri);
} catch (Exception e) {
System.out.println("Problem creating document: "+e.getMessage());
}
}
public static void main(String[] argv) {
Untitled1 untitled11 = new Untitled1();
untitled11.readXML(argv[0]);
}
}
这是我的程序,但运行报错:
Problem creating document: no protocol: sonnet.xml
不知何故,请教
|
如:file、Http、Ftp、Ghoper等