Auf Thema antworten

Ui, da ist mir ein Fehler beim Einfügen passiert ... hier nochmal der Code, der Parser Klasse:


[code=Java]


public class DescParser extends DefaultHandler {


    private final File DER_DESC = new File(...);

    private final String SW_ID = "...";

    private final String ISIN = "isin";


    private List<String> swid_list = new ArrayList<String>();


    public List<String> parseIt() {

        try {

            SAXParserFactory factory   = SAXParserFactory.newInstance();

            SAXParser        saxParser = factory.newSAXParser();

            DefaultHandler   handler   = new DescParser();

            saxParser.parse(DER_DESC, handler);


        } catch (SAXException e) {

            e.printStackTrace();      //To change body of catch statement use File | Settings | File Templates.

        } catch (IOException e) {

            e.printStackTrace();                       //To change body of catch statement use File | Settings | File Templates.

        } catch (ParserConfigurationException e) {

            e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.

        }

        return swid_list;

    }


    private HashMap<String, String> descMap = new HashMap<String, String>();


    @Override

    public void startDocument()

    {

        System.out.println("Document starts.");

    }


    @Override

    public void endDocument()

    {

        System.out.println("Document ends.");


    }


    private String   attr;

    private String[] values = new String[2];

    int count = 0;


    @Override

    public void startElement(String namespaceURI, String localName, String qName, Attributes atts)

    {

        attr = "";


        if (atts.getValue(0) != null) {

            if (atts.getValue(0).equals(SW_ID))

            {

                attr = atts.getValue(0);

            }

        }

    }


    @Override

    public void endElement(String uri, String localName, String qName)

    {

        if (attr.equals(SW_ID)) {

            swid_list.add(buffer.toString());

        }


    }


    private StringBuffer buffer = new StringBuffer();

  

    @Override

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

    {

        buffer.delete(0, buffer.length());

        buffer.append(ch, start, length);

    }


}


[/code]


So jetzt sollte es passen



Oben