Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Edit an XML file with SAX

843834Nov 6 2006 — edited Nov 8 2006
Dear all, I am so confused�.
I have been trying for the last few days to understand how sax works� The only thing I understood is:
DefaultHandler handler = new Echo01();
 SAXParserFactory factory = SAXParserFactory.newInstance();
        try {
            out = new OutputStreamWriter(System.out, "UTF8");
            SAXParser saxParser = factory.newSAXParser();
            saxParser.parse(file , handler);
        } catch (Throwable t) {
            t.printStackTrace();
        }
        System.exit(0);
    }
Ok, I assign the SAXParser the xml file and a handler. The parser parses and throws events that the handler catches. By implementing some handler interface or overriding the methods of an existing handler (e.g DeafultHandler class) I get to do stuff�
But still, suppose I have implement startElement() method of DefaultHandler class and I know that the pointer is currently placed on an element e.g. <name>bob</name>. How do I get the value of the element, and if I manage to do that, how can I replace�bob� with �tom�?

I would really appreciate any help given� just don�t recommend http://java.sun.com/webservices/jaxp/dist/1.1/docs/tutorial/ because although there are interesting staff in there, it does not solve my problem�
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 6 2006
Added on Nov 6 2006
3 comments
289 views