不会吧,我刚刚接触xml,这个问题这么难???
解决方案 »
- 大家好,请帮我看下我的这段代码怎么不能修改数据
- 求助:调试一段代码时,在其中某行停止了
- 请高手帮忙 关于使用jar的问题
- java与cgi通信问题
- 请问java的locale本地化是什么一回事?
- 如何实例化一个DateInputStream?
- html:option 标签中的value值,如何从资源文件中读取数据?超着急......在线等待!!!!!!
- 关于汉化的问题,高分(100)
- JAVA连接SQL SERVER数据库的怪问题
- 帮我看一段程序,为什么会发生这样的错误,谢谢,我用的工具是JCREATOR
- 菜鸟级问题一个,愿者请进。
- jb5的jdk似乎运行rmi有点问题,同时那位的jb5的注册吗有效?
<!DOCTYPE WBServer SYSTEM "wbserver.dtd">
<WBServer id="test">
<Class id="computer" max_group="32">
<Group id="nudt" basedir="data\computer\nudt\" issue_mode="teach" max_client="20" max_lock_time="1" max_user="256" max_page="256">
<Teacher id="sam" password="123"/>
<Teacher id="ssg2" password="123"/> <Student id="wave" password="123"/>
<Student id="coco" password="123"/>
<Student id="foo" password="123"/>
<Student id="hehe" password="123"/>
<Student id="kang" password="123"/>
<Student id="icestar" password="123"/>
<Student id="uzcce" password="123"/>
<Student id="kiki" password="123"/>
<Student id="mudu" password="123"/>
<Student id="half" password="123"/> </Group>
<Group id="tsh" basedir="data\computer\tsh\" issue_mode="teach" max_client="2" max_lock_time="5" max_user="256" max_page="256">
<Teacher id="don" password="123"/> <Student id="wave" password="123"/>
<Student id="half" password="123"/> </Group>
</Class>
</WBServer>import java.util.Hashtable;
import java.util.Vector;
import java.util.Enumeration;
import java.io.IOException;
import java.io.Serializable;
import java.io.File;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.net.ServerSocket;
import java.net.Socket;import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.SQLException;import javax.swing.JPanel;
import javax.swing.BorderFactory;
import javax.swing.JSplitPane;import javax.xml.parsers.SAXParserFactory;
import javax.xml.parsers.SAXParser;
import org.xml.sax.Attributes;
import org.xml.sax.XMLReader;
import org.xml.sax.ErrorHandler;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import org.xml.sax.helpers.DefaultHandler;
public class readxml extends DefaultHandler implements Serializable,ErrorHandler{ public static final int LOGIN_OK = 0;
public static final int LOGIN_FAIL = 1;
public static final int LOGIN_ALREADY = 2;
JSplitPane pane;
int Port = 1701;
int Max_Class_Num = 10;
int Max_Client_Num = 100;
int Kick_Free_Time = 10;
String dbDriver = "org.gjt.mm.mysql.Driver";
String dbUser;
String dbPassword;
// DataBase Connection format jdbc:mysql://hostname/dbname
String connStr = "jdbc:mysql://172.26.2.44/wb?user=wb&password=whiteboard";
Vector hClasses;
Vector hClients;
ServerSocket lsnSock;
boolean run_f = false;
Connection dbConn;
Thread thisThread;
public readxml(){
}
public void readConfigFile(String filename){
try{
readConfigFile(new File(filename));
}catch(Exception e){
e.printStackTrace();
}
}
public void readConfigFile(File file){
System.out.println("file is: "+file);
SAXParserFactory saxFact = SAXParserFactory.newInstance();
saxFact.setValidating(true);
try{
XMLReader xmlReader = saxFact.newSAXParser().getXMLReader();
xmlReader.setContentHandler(this);
xmlReader.setErrorHandler(this);
xmlReader.parse(file.toURL().toString());
}catch(Exception e){
System.out.println("******error********");
e.printStackTrace();
}
}
private String getParseExceptionInfo(SAXParseException spe) {
String systemId = spe.getSystemId();
if (systemId == null) {
systemId = "null";
}
String info = "URI=" + systemId +
" Line=" + spe.getLineNumber() +
": " + spe.getMessage();
return info;
}
public void warning(SAXParseException spe)throws SAXException{
System.out.println("Warning: "+getParseExceptionInfo(spe));
}
public void error(SAXParseException spe)throws SAXException{
throw new SAXException("Error: "+getParseExceptionInfo(spe));
}
public void fatalError(SAXParseException spe)throws SAXException{
throw new SAXException("Fatal Error: "+getParseExceptionInfo(spe));
}
public void startDocument()throws SAXException{
System.out.println("XML startDocument");
}
public void endDocument()throws SAXException{
}
public static int getInt(String s){
return (new Integer(s)).intValue();
}
public static String getStr(String s){
try{
return new String(s.getBytes("ISO8859-1"));
}catch(Exception e){
e.printStackTrace();
return "ERROR";
}
}
public void startElement(String nsURI,String localName,String rawName,Attributes atts)throws SAXException{
if (localName.equals("WBServer")){
Port = getInt(atts.getValue("port"));
Max_Class_Num = getInt(atts.getValue("max_class"));
Max_Client_Num = getInt(atts.getValue("max_client"));
dbDriver = atts.getValue("JDBCDriver");
connStr = atts.getValue("url");//+"?user="+atts.getValue("user")+"&password="+atts.getValue("password");
dbUser = atts.getValue("user");
dbPassword = atts.getValue("password"); hClasses = new Vector(Max_Class_Num);
hClients = new Vector(Max_Client_Num);
}else if (localName.equals("Class")){
hClasses.add( getStr(atts.getValue("id")) );
System.out.println(getStr(atts.getValue("id")) );
}else if (localName.equals("Group")){
System.out.println(getStr(atts.getValue("id")));
}else if (localName.equals("Teacher")){
System.out.println(getStr(atts.getValue("id")));
}else if (localName.equals("Student")){
System.out.println(getStr(atts.getValue("id")));
}
}
public void endElement(String uri,String localName,String qName)throws SAXException{
if (localName.equals("Class")){
}else if (localName.equals("Group")){
}else if (localName.equals("Teacher")){
}else if (localName.equals("Student")){
}
}
public static void main(String argv[]){
System.out.println("hi allllll");
readxml rx = new readxml();
rx.readConfigFile("wbserver.xml");
}
}编译通过,连“hi allllll”都打印不出来.
还打印了下面两句:
file is: wbserver.xml
XML startDocument
后面出错了.
我的是,jdk1.3, jre1.3.1, 还有就是从sun上下载的三个关于xml的jar包,
crimson.jar, jaxp.jar, xalan.jar.
windows 2000