struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject urgent please -- XML document reading/parsing through SAX for the given snippet.
Date Mon, 23 Feb 2004 10:07:04 GMT

I need to parse an xml document (xml file) using SAX API.

A portion of the .xml file looks as follows (for displaying 1 row of

<case id="RMA-1234">
      <assigned-to>Abrao I. Grynglas</assigned-to>
      <subject>This is the subject of email</subject>
      <status>Document Open</status>

I use the following java source code to do the same.
class MyHandler extends DefaultHandler
      private Set Cases = new TreeSet();
      private String strCase = "";
      public MyHandler(){}
      public void startElement(String namespaceURI,String localname,String
rawname,Attributes atts) throws SAXException
            if (localname.equals("case"))
                  for (int i = 0; i < atts.getLength(); i++)
                        String attName = atts.getLocalName(i);
                        if (attName.equals("id"))
                        strCase = atts.getValue(i);
      public void endElement(String namespaceURI,String localname,String
rawname) throws SAXException
            if (localname.equals("case"))
                  String thisCase = strCase.toString().trim();
      public void characters(char [] buf,int offset,int len){
            String partOfCaseName = new String(buf, offset, len);
      public Set getCases(){
            return Cases;

So the above code returns only the attribute values from the first main element
"case".  I would also like to retrieve (using SAX) the values of simple elements
also.  Can anyone guide me how to achieve this, please ?

Thanks and Regards
S Srikanth

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message