可以呀,取出数据生成XML文件,在解析,不只楼主要做什么?

解决方案 »

  1.   

    不好意思打错了可以呀,取出数据后生成XML文件,再用SAX解析这个文件,
    不知楼主要做什么?
      

  2.   

    public class XMLReader { public void list() throws Exception {
    SAXParser parser = new SAXParser();
    parser.setContentHandler(new PeopleHandler());
    parser.parse("people.xml"); } public static void main(String[] args) throws Exception {
    new XMLReader().list();
    }}class PeopleHandler extends DefaultHandler { private boolean name = false;
    private boolean mail = false;
    private Properties property = null;
    private StringBuffer sb = new StringBuffer(); public PeopleHandler() {
    property = new Properties();
    } public void startElement(
    String nsURI,
    String stripName,
    String tagName,
    Attributes attributes)
    throws SAXException {
    sb.delete(0, sb.length());
    } public void characters(char[] ch, int start, int length)
    throws SAXException {
    sb.append(ch, start, length);
    } public void endElement(String nsURI, String stripName, String tagName)
    throws SAXException {
    property.put(tagName, sb.toString().trim());
    sb.delete(0, sb.length());
    System.out.println( property.getProperty(tagName));
    } public void printXML() {
    Enumeration propertyNames = property.propertyNames();
    while (propertyNames.hasMoreElements()) {
    String propertyName = (String) propertyNames.nextElement();
    System.out.println("PropertyName" + propertyName);
    System.out.println("Value" + property.getProperty(propertyName));
    }
    }
    }
      

  3.   

    <?xml version="1.0"?>
    <people>
    <person>
    <name>fantasyCoder</name>
    <email>[email protected]</email>
    </person>
    </people>
      

  4.   

    简单的例子!不知对你有无帮助SAX解析XML是基于事件的!