回车、换行符等空白字符也会触发characters事件,加上ignorableWhitespace()处理一下
解决方案 »
- 华为smproxy SMPP 使用报错The constructor SMPPSubmitMessage(String···) is undefined
- 嘗試把while loop的東西重寫成for loop + if,但結果不相同,該怎麽改?
- JAVA里有没类似VB可以输入数据的对话框?
- jvm在什么时候有机会调用ShutdownHook?为何我addShutdownHook()加进去的善后操作从来没有被执行过?高手请进来解释,拿分
- 高手请进
- 此论坛的高手都不在吗?初次接触java,是看了 java.lang.reflect.Proxy 的newProxyInstance方法 的源码30分钟后, 头晕了。
- 我是个JAVA的初学者,我在学习JAVA的简单数据类型时看到(byte、int、short等等)都有一些(byte byteValue()等)方法,但如何使用不会
- 为什么关闭Java程序的时候,总会弹出一个微软拼音的"关于"对话框来
- 在线程a中使线程b结束,语句应怎样写?
- 求大神帮帮忙,关于读取txt文件,用string array
- 关于Image装载问题,请高手帮忙
- #求JFC 核心编程的电子版本
怎么会是6次的呢??
弄代码来看看把
private java.util.Stack tags = new java.util.Stack();
private TB_TenorNoticeBookVO tb_tenorNoticBookVO = new TB_TenorNoticeBookVO();
private ContentHandler parentHandler;
public void setParentHandler(DefaultHandler parentHandler) {
this.parentHandler = parentHandler;
} public void startElement(String uri, String localName, String tag,
Attributes attribs)
throws SAXParseException {
System.out.println(localName);
tags.push(localName);
} /* public void ignorableWhitespace (char ch[], int start, int length)
throws SAXException{
System.out.println("dddddddddddddddddddddddddddddddddddddddd");
//characters(ch, start, length);
} */
/**
*
*
* @param buf
* @param start
* @param length
* @throws SAXParseException
*/
public void characters(char[] buf, int start, int length)
throws SAXParseException { String tag = "";
if (!tags.isEmpty())
tag = (String) tags.peek(); String temp = new String(buf, start, length);
System.out.println("value=================" + temp + " length====="+temp.length());
if (tag.equals("ID"))
tb_tenorNoticBookVO.setId(temp);
else if (tag.equals("CHECKCODE"))
tb_tenorNoticBookVO.setCheckcode(temp);
else if (tag.equals("CONTENT"))
tb_tenorNoticBookVO.setContent(temp);
else if (tag.equals("ENDDATE")) {
Timestamp timestamp = TimeUtil.getTimeOfTimeStr(temp);
tb_tenorNoticBookVO.setEnddate(timestamp);
}else if (tag.equals("SENDUNIT"))
tb_tenorNoticBookVO.setSendunit(temp);
else if (tag.equals("WFXW"))
tb_tenorNoticBookVO.setWfxw(temp);
else if (tag.equals("UNITADMIN"))
tb_tenorNoticBookVO.setUnitadmin(temp);
else if (tag.equals("ADMINSIGNDATE")){
Timestamp timestamp = TimeUtil.getTimeOfTimeStr(temp);
tb_tenorNoticBookVO.setAdminsigndate(timestamp);
}
} /**
*
* @param uri
* @param localName
* @param tag
* @throws SAXParseException
*/
public void endElement(String uri, String localName, String tag)
throws SAXParseException {
System.out.println(localName);
startElementFlag=false;
if (localName.equals("TENORNNOTICEBOOK")) {
DataOperator dataOperator = DataOperatorFactory.getTenorNotictBookInstance();
try {
//dataOperator.insertRecord(tb_tenorNoticBookVO);
} catch (Exception e) {
}
parser.setContentHandler(parentHandler);
} else {
while (!tags.empty())
tags.pop();
}
}
}
回车 2.bbbb 回车 3.cccc
这样在解析的时候就会出现问题了,
msn [email protected]
qq 7766284请联系我,谢谢
import org.xml.sax.helpers.*;
import org.xml.sax.*;
import java.util.*;
/**
* <p>Title: basic core</p>
* <p>Description: zealvampire</p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company: zealvampire</p>
* @author zeal
* @version 1.0
*/public class simpleSaxParser extends DefaultHandler {
private String name=null;
private StringBuffer value=null;
private HashMap hMap=null; public simpleSaxParser() {
}
public void startDocument( ) throws SAXException {
System.out.println("---SAX Event: START DOCUMENT---");
this.hMap=new HashMap();
this.value=new StringBuffer();
} public void endDocument( ) throws SAXException {
System.out.println("---SAX Event: END DOCUMENT---");
} public void startElement( String namespaceURI,String localName,String qName,Attributes attr ) throws SAXException {
System.out.println("SAX event:startElement["+localName+"]");
if(localName.equals("param")){
this.value.setLength(0);
this.name = attr.getValue("name");
}
} public void endElement( String namespaceURI,String localName,String qName ) throws SAXException {
System.out.println("sax event:endElement["+localName+"]");
if(localName.equals("param")){
this.hMap.put(this.name,this.value.toString().trim());
this.value.setLength(0);
}
} public void characters( char[] ch, int start, int length ) throws SAXException{
this.value.append(ch,start,length);
} private void printError(SAXParseException exception){
System.out.println("\t行:\t" + exception.getLineNumber());
System.out.println("\t列:\t" + exception.getColumnNumber());
System.out.println("\t错误信息:\t" + exception.getMessage());
System.out.println("-------------------");
}
public void warning( SAXParseException exception ) {
System.out.println("------WARNING------");
this.printError(exception);
} public void error( SAXParseException exception ) throws SAXException{
System.out.println("------ ERROR ------");
this.printError(exception);
} public void fatalError( SAXParseException exception ) throws SAXException {
System.out.println("------ FATAL ERROR ------");
this.printError(exception);
} public HashMap getResult(){
return this.hMap;
}
}
<parameter>
<sys>
<param name="INITIAL_CONTEXT_FACTORY">org.jnp.interfaces.NamingContextFactory</param>
<param name="PROVIDER_URL">localhost:1099</param>
<param name="URL_PKG_PREFIXES">org.jboss.naming:org.jnp.interfaces</param>
<param name="SECURITY_PRINCIPAL">test_user</param>
<param name="SECURITY_CREDENTIALS">test_pass</param>
<param name="名字">1.ddd
2.ddd3.ccc</param>
</sys>
</parameter>