public class SAXtest extends DefaultHandler { public void endDocument() throws SAXException {
System.out.println("------Parse End--------");
}
public void startDocument() throws SAXException {
System.out.println("------Parse Begin--------");
}
public void startElement(String p0, String p1, String p2, Attributes p3) throws SAXException {
//p2是名比如<name>的name
//p3是属性
}
public void endElement(String p0, String p1, String p2) throws SAXException {}
public void characters(char[] p0, int p1, int p2) throws SAXException {
String temp=new String(p0,p1,p2);
//temp就是Hitler,或者1这些值
}}
System.out.println("------Parse End--------");
}
public void startDocument() throws SAXException {
System.out.println("------Parse Begin--------");
}
public void startElement(String p0, String p1, String p2, Attributes p3) throws SAXException {
//p2是名比如<name>的name
//p3是属性
}
public void endElement(String p0, String p1, String p2) throws SAXException {}
public void characters(char[] p0, int p1, int p2) throws SAXException {
String temp=new String(p0,p1,p2);
//temp就是Hitler,或者1这些值
}}
解决方案 »
- 自己开发的MailServer 外发邮件实现
- 用Java,用什么实现在线聊天?dwr,coment。。。
- Birt怎么在tomcat 6.0里边配置
- eclipse中hibernate插件的使用
- 紧急求助: 我用ireport 2.0.5制作的报表怎么不出表格线!ireport侧生成pdf文件是可看到表格线的,但java程序里用到它对应的.jasper时,生成的报表却没有表格线,这是为什么!!!!
- 请问这条语句什么意思?在哪里实现这条语句呢?jdbc:oracle:thin:@126.21.44.172:8022:cissdev
- 想在天津找java工作的来这里看看,这里有几道笔试题目,也许你会遇到哦。
- 谁能帮忙提供OFBiz?今天怎么搞的,网站上根本找不到下载的链接了!多谢!
- 晕!最后一步崩溃!高分求解在weblogic部署EAR问题
- 100分,请教EJB的事务问题
- Java如何实现多用户视频?
- tomcat5.5 关于 Servlet 的编译问题本人还是有疑问阿??
这是解析,还是不能解决应用问题。我的意思是一个order Node就是一个hashtable,但如何在解析过程中把这些hashtable插入在collention对象中去,并能通过取key值或遍历中得到具体应用。寡,GUA,寡人,孤家寡人,寡妇。
你又想怎么遍历?
我不想瞎忙活。。
处理过程中要用到栈。
具体你要以什么结构实现这些来封装这些hashtable?
String lName,
String qName,
Attributes attrs) throws SAXException {
String eName = lName;
if ("".equals(eName))
eName = qName;
lastElement = eName;
if (attrs != null) {
for (int i = 0; i < attrs.getLength(); i++) {
String aName = attrs.getLocalName(i);
if ("".equals(aName))
aName = attrs.getQName(i);
if (aName.equals("about") || aName.equals("rdf:about")) //只把about属性加入结果集
add2Map(aName, attrs.getValue(i));
} }
} public void endElement(String namespaceURI,
String sName,
String qName) throws SAXException { if (sName.equals("Description") || qName.equals("rdf:Description")) {
Object value = tags.get("label");
if (value != null) {
ArrayList temp = (ArrayList) value;
for (int i = 0; i < temp.size(); i++) {
if ( ( (String) temp.get(i)).toLowerCase().indexOf(searchKey) != -1) {
resultArray.add(tags); }
}
}
tags = null;
} }
不好意思,最近比较忙没有回你。
我已经用数组和哈希表解决了这个问题了,得到的结果是hashtable组
import java.util.Hashtable;
import org.xml.sax.*;public class SAXHandler extends HandlerBase
{
private Hashtable table = new Hashtable();
private String currentElement = null;
private String currentValue = null;
private int i = 0;
private Hashtable[] arrayHashtable = new Hashtable[20];//定单最多支持20个node
public Hashtable getTable(){
return table;
}
public Hashtable[] getArrayHashtable()
{
return arrayHashtable;
} public void startElement(String tag,AttributeList attrs)
throws SAXException
{
currentElement = tag;
}
public void characters(char[] ch,int start,int length)
throws SAXException
{
currentValue = new String(ch,start,length);
}
public void endElement(String name)
throws SAXException
{
if (currentElement.equals(name))
table.put(currentElement,currentValue);
if (name.equals("person"))
{
Hashtable copyTable = (Hashtable)table.clone();
arrayHashtable[i] = copyTable
i++;
table.clear();
}
}
}
欢迎下次再来探讨这些应用问题。
CSDN多是些菜鸟水客,真正有用的帖子很快就淹没了没人管。