当前位置: 技术问答>java相关
初学者关于java与xml的问题
来源: 互联网 发布时间:2015-07-15
本文导语: 各位好,请你们帮个忙。我调试一个关于JAVA与XML地程序,但是出现了三个错误: C:jdk1.4bin>javac e:Connectprice.java e:Connectprice.java:8: package org.apache.xerces.parsers does not exist import org.apache.xerces.parsers.DOMParser; ...
各位好,请你们帮个忙。我调试一个关于JAVA与XML地程序,但是出现了三个错误:
C:jdk1.4bin>javac e:Connectprice.java
e:Connectprice.java:8: package org.apache.xerces.parsers does not exist
import org.apache.xerces.parsers.DOMParser;
^
e:Connectprice.java:111: cannot resolve symbol
symbol : class DOMParser
location: class bean.Connectprice
DOMParser MyParser = new DOMParser();
^
e:Connectprice.java:111: cannot resolve symbol
symbol : class DOMParser
location: class bean.Connectprice
DOMParser MyParser = new DOMParser();
^
Note: e:Connectprice.java uses or overrides a deprecated API.
Note: Recompile with -deprecation for details.
3 errors
有个人是这样回复我的:
org.apache.xerces.parsers.DOMParser
你用apache的xerces来解析xml, 你不把它的jar放到路径里行吗?
我不太懂他的意思,我如何把他所说的JAR放在该放的地方呢?
我用的是JRUN3.0,JDK1.4,同时我也下载了Xerces-J-tools.2.0.2.zip并解压缩到TOOL目录下。但是我不知道这么用,希望各位能帮帮忙,
另外我不知道是否需要APACHE,我的机器里不装。
谢谢各位的参与,希望给出宝贵建议。分必送。
以下是调试的程序:
package bean;
import java.io.*;
import java.net.*;
import java.util.*;
import java.sql.*;
import org.xml.sax.*;
import org.w3c.dom.*;
import org.apache.xerces.parsers.DOMParser;
import javax.xml.parsers.*;
import javax.xml.transform.stream.*;
import javax.xml.transform.*;
import javax.xml.transform.dom.*;
public class Connectprice{
String backxml="";
ResultSet rset=null;
Connection conn =null;
Statement stmt =null;
String localname="",sql="";
String attribute="";
String flightNo="FlightNo",airline="";
String flightvalue="FlyDate",classes="";
String fromcity="FromCity";
String tocity="ToCity";
String startdate="DTime";
String enddate="";
//与服务器连接
public void sendxml(String xml){
Socket socket;
String len;
InputStream Is;
OutputStream Os;
DataInputStream DIS;
PrintStream PS;
try{
//向主机名为args[0]的服务器申请连接
//注意端口号要与服务器保持一致:1001
socket=new Socket("10.21.5.19",1001);
System.out.println("client ok");
System.out.println("************************************************");
System.out.println("");
//获得对应socket的输入/输出流
Is=socket.getInputStream();
Os=socket.getOutputStream();
//建立数据流
DIS=new DataInputStream(Is);
PS = new PrintStream(Os);
System.out.print("you say:"+xml);
PS.print(xml); //将读取得字符串传给server
System.out.println("");
System.out.println("please wait server`s message...");
System.out.println("");
backxml=DIS.readLine(); //从服务器获得字符串
System.out.println("server said:"+backxml); //打印字符串
//关闭连接
DIS.close(); //关闭数据输入流
PS.close(); //关闭数据输出流
Is.close(); //关闭输入流
Os.close(); //关闭输出流
socket.close(); //关闭socket
}
catch(Exception e){
System.out.println("连接Error:"+e);
}
}
//建立xml文档
public void writexml(){
String Filename="e:\try\web-inf\classes\fxml.xml";
BufferedWriter fos;
System.out.println(backxml);
try {
fos = new BufferedWriter(new FileWriter((new File(Filename))));
fos.write(backxml);
fos.flush();
} catch(IOException e) {
System.out.println("写文档时发生io错误");
}
}
//数据库连接
public void openConnection() throws ClassNotFoundException,SQLException {
this.conn=DriverManager.getConnection( "jdbc:odbc:airwork;","sa","");
}
public void executequery(String query) throws SQLException {
this.stmt=conn.createStatement();
this.rset=stmt.executeQuery(query);
}
public void executeupdate(String query) throws SQLException {
this.stmt=conn.createStatement();
stmt.executeUpdate(query);
if (stmt!=null) stmt.close();
}
public void close() throws SQLException {
if (conn!=null) conn.close();
if (rset!=null) rset.close();
if (stmt!=null) stmt.close();
}
//开始XML解析
public void ParseDoc() throws ClassNotFoundException,SQLException
{
try
{
writexml();
openConnection();
DOMParser MyParser = new DOMParser();
MyParser.parse("e:\try\web-inf\classes\fxml.xml");
Document XMLDoc = MyParser.getDocument();
printNode(XMLDoc);
close();
}
catch (IOException e)
{
System.out.println("解析出错Error IOException!!!");
}
catch (SAXException e)
{
System.out.println("Error SAXException!!!");
}
}
public void printNode(Node node) throws ClassNotFoundException,SQLException
{
if (node.getNodeType() == Node.DOCUMENT_NODE)
{
System.out.println("DOCUMENT_NODE");
NodeList nodelist = node.getChildNodes();
if (nodelist != null)
{
for (int ii = 0; ii
C:jdk1.4bin>javac e:Connectprice.java
e:Connectprice.java:8: package org.apache.xerces.parsers does not exist
import org.apache.xerces.parsers.DOMParser;
^
e:Connectprice.java:111: cannot resolve symbol
symbol : class DOMParser
location: class bean.Connectprice
DOMParser MyParser = new DOMParser();
^
e:Connectprice.java:111: cannot resolve symbol
symbol : class DOMParser
location: class bean.Connectprice
DOMParser MyParser = new DOMParser();
^
Note: e:Connectprice.java uses or overrides a deprecated API.
Note: Recompile with -deprecation for details.
3 errors
有个人是这样回复我的:
org.apache.xerces.parsers.DOMParser
你用apache的xerces来解析xml, 你不把它的jar放到路径里行吗?
我不太懂他的意思,我如何把他所说的JAR放在该放的地方呢?
我用的是JRUN3.0,JDK1.4,同时我也下载了Xerces-J-tools.2.0.2.zip并解压缩到TOOL目录下。但是我不知道这么用,希望各位能帮帮忙,
另外我不知道是否需要APACHE,我的机器里不装。
谢谢各位的参与,希望给出宝贵建议。分必送。
以下是调试的程序:
package bean;
import java.io.*;
import java.net.*;
import java.util.*;
import java.sql.*;
import org.xml.sax.*;
import org.w3c.dom.*;
import org.apache.xerces.parsers.DOMParser;
import javax.xml.parsers.*;
import javax.xml.transform.stream.*;
import javax.xml.transform.*;
import javax.xml.transform.dom.*;
public class Connectprice{
String backxml="";
ResultSet rset=null;
Connection conn =null;
Statement stmt =null;
String localname="",sql="";
String attribute="";
String flightNo="FlightNo",airline="";
String flightvalue="FlyDate",classes="";
String fromcity="FromCity";
String tocity="ToCity";
String startdate="DTime";
String enddate="";
//与服务器连接
public void sendxml(String xml){
Socket socket;
String len;
InputStream Is;
OutputStream Os;
DataInputStream DIS;
PrintStream PS;
try{
//向主机名为args[0]的服务器申请连接
//注意端口号要与服务器保持一致:1001
socket=new Socket("10.21.5.19",1001);
System.out.println("client ok");
System.out.println("************************************************");
System.out.println("");
//获得对应socket的输入/输出流
Is=socket.getInputStream();
Os=socket.getOutputStream();
//建立数据流
DIS=new DataInputStream(Is);
PS = new PrintStream(Os);
System.out.print("you say:"+xml);
PS.print(xml); //将读取得字符串传给server
System.out.println("");
System.out.println("please wait server`s message...");
System.out.println("");
backxml=DIS.readLine(); //从服务器获得字符串
System.out.println("server said:"+backxml); //打印字符串
//关闭连接
DIS.close(); //关闭数据输入流
PS.close(); //关闭数据输出流
Is.close(); //关闭输入流
Os.close(); //关闭输出流
socket.close(); //关闭socket
}
catch(Exception e){
System.out.println("连接Error:"+e);
}
}
//建立xml文档
public void writexml(){
String Filename="e:\try\web-inf\classes\fxml.xml";
BufferedWriter fos;
System.out.println(backxml);
try {
fos = new BufferedWriter(new FileWriter((new File(Filename))));
fos.write(backxml);
fos.flush();
} catch(IOException e) {
System.out.println("写文档时发生io错误");
}
}
//数据库连接
public void openConnection() throws ClassNotFoundException,SQLException {
this.conn=DriverManager.getConnection( "jdbc:odbc:airwork;","sa","");
}
public void executequery(String query) throws SQLException {
this.stmt=conn.createStatement();
this.rset=stmt.executeQuery(query);
}
public void executeupdate(String query) throws SQLException {
this.stmt=conn.createStatement();
stmt.executeUpdate(query);
if (stmt!=null) stmt.close();
}
public void close() throws SQLException {
if (conn!=null) conn.close();
if (rset!=null) rset.close();
if (stmt!=null) stmt.close();
}
//开始XML解析
public void ParseDoc() throws ClassNotFoundException,SQLException
{
try
{
writexml();
openConnection();
DOMParser MyParser = new DOMParser();
MyParser.parse("e:\try\web-inf\classes\fxml.xml");
Document XMLDoc = MyParser.getDocument();
printNode(XMLDoc);
close();
}
catch (IOException e)
{
System.out.println("解析出错Error IOException!!!");
}
catch (SAXException e)
{
System.out.println("Error SAXException!!!");
}
}
public void printNode(Node node) throws ClassNotFoundException,SQLException
{
if (node.getNodeType() == Node.DOCUMENT_NODE)
{
System.out.println("DOCUMENT_NODE");
NodeList nodelist = node.getChildNodes();
if (nodelist != null)
{
for (int ii = 0; ii