1

以下のコードでは、ノード内の各データに対して SAX パーサーからデータの配列を返したいと考えています。各リーフノードの下にデータを保持する配列リストがあります。このデータをハンドラーの外で使用したり、返すにはどうすればよいですか? -

public class ReadXMLFile {

   public static xmldataparser(String argv[]) {

    try {

    SAXParserFactory factory = SAXParserFactory.newInstance();
    SAXParser saxParser = factory.newSAXParser();

    DefaultHandler handler = new DefaultHandler() {

    boolean burl = false;
    boolean bip = false;
    List<String> a = new ArrayList<String>();

    public void startElement(String uri, String localName,String qName, 
                Attributes attributes) throws SAXException {

        System.out.println("Start Element :" + qName);

        if (qName.equalsIgnoreCase("URL")) {
            burl = true;
        }

        if (qName.equalsIgnoreCase("IP")) {
            bip = true;
        }



    }

    public void endElement(String uri, String localName,
        String qName) throws SAXException {

        System.out.println("End Element :" + qName);

    }

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

        if (burl) {
            System.out.println("URL : " + new String(ch, start, length));
            a.add(new String(ch, start, length));
            burl = false;
        }

        if (bip) {
            System.out.println("IP : " + new String(ch, start, length));
            bip = false;
            a.add(new String(ch, start, length));
        }


    }

     };
  }
return <the array from the handler(this is where I need help)>
 }
}
4

2 に答える 2