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这些值
}}

解决方案 »

  1.   

    to xitianjile(西天):
    这是解析,还是不能解决应用问题。我的意思是一个order Node就是一个hashtable,但如何在解析过程中把这些hashtable插入在collention对象中去,并能通过取key值或遍历中得到具体应用。寡,GUA,寡人,孤家寡人,寡妇。
      

  2.   

    你到底要插入一个什么样类型的hashtable中?
    你又想怎么遍历?
    我不想瞎忙活。。
    处理过程中要用到栈。
    具体你要以什么结构实现这些来封装这些hashtable?
      

  3.   

    public void startElement(String namespaceURI,
                               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;
        }  }
      

  4.   

    to xitianjile(西天):
    不好意思,最近比较忙没有回你。
    我已经用数组和哈希表解决了这个问题了,得到的结果是hashtable组
      

  5.   

    package com.fastfan.xml.SAX;
    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();
        }
      }
    }
      

  6.   

    不好意思,300分不给了。
    欢迎下次再来探讨这些应用问题。
    CSDN多是些菜鸟水客,真正有用的帖子很快就淹没了没人管。