以文本方式查看主题

-  中文XML论坛 - 专业的XML技术讨论区  (http://bbs.xml.org.cn/index.asp)
--  『 DOM/SAX/XPath 』  (http://bbs.xml.org.cn/list.asp?boardid=11)
----  求助]请大家帮我看看这段SAX解析XML文件的代码 [求助]  (http://bbs.xml.org.cn/dispbbs.asp?boardid=11&rootid=&id=15196)


--  作者:zhangbo198294
--  发布时间:3/7/2005 1:52:00 PM

--  求助]请大家帮我看看这段SAX解析XML文件的代码 [求助]
import javax.xml.parsers.*;
import org.xml.sax.*;
import org.xml.sax.helpers.*;
import java.io.*;
public class SaxXml {
  // 重载DefaultHandler类的方法
    // 以拦截SAX事件通知。
    //
         // 关于所有有效事件,见org.xml.sax.ContentHandler
    //
    public void startDocument( ) throws SAXException {
       System.out.println( "SAX Event: START DOCUMENT" );
    }

    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: START ELEMENT[ " +
                   localName + " ]" );

       // 如果有属性,我们也一并打印出来...
                 for ( int i = 0; i < attr.getLength(); i++ ){
                    System.out.println( "   ATTRIBUTE: " + attr.getLocalName(i) + " VALUE: " + attr.getValue(i) );
       }

    }

    public void endElement( String namespaceURI, String localName, String qName ) throws SAXException {
       System.out.println( "SAX Event: END ELEMENT[ "+localName + " ]" );
    }

    public void characters( char[] ch, int start, int length )
                   throws SAXException {

       System.out.print( "SAX Event: CHARACTERS[ " );

       try {
          OutputStreamWriter outw = new OutputStreamWriter(System.out);
          outw.write( ch, start,length );
          outw.flush();
       } catch (Exception e) {
          e.printStackTrace();
       }

       System.out.println( " )" );

    }


    public static void main( String[] argv ){

       System.out.println( "Example1 SAX Events:" );
       try {

           //  SAXParserFactory  spFactory = SAXParserFactory.newInstance();
          // SAXParser sParser = spFactory.newSAXParser();


          // 建立SAX 2解析器...
          XMLReader xr = XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser");

          // 安装ContentHandler...
          xr.setContentHandler( new SaxTest() );

             // 解析文件...
          xr.parse( new InputSource(
                new FileReader( "exampleA.xml" )) );


       }catch ( Exception e )  {
          e.printStackTrace();
       }

    }

 }

  xr.setContentHandler( new SaxTest() );
   报错说找不到SaxTest这个类 请问这个类在哪个包里面啊?

  


--  作者:doubleG
--  发布时间:3/8/2005 6:18:00 PM

--  
是自己写的类吧
--  作者:roarhaole
--  发布时间:3/16/2005 10:10:00 AM

--  
SaxTest似乎不是java类库里的东西吧!!
--  作者:zhangbo198294
--  发布时间:3/17/2005 9:51:00 AM

--  
是自己写错了呵呵
--  作者:dfsfsdf
--  发布时间:3/21/2005 5:47:00 PM

--  
我也不懂啊

http://www.hczjg.com/kook1/upload/009/plmm.swf


W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
1,328.125ms