struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Marco Mistroni" <mmistr...@waersystems.com>
Subject RE: urgent please -- XML document reading/parsing through SAX for the given snippet.
Date Mon, 23 Feb 2004 12:00:24 GMT
Hi,
	Check on the net for SAX handlers examples...you have
To maintain the state yourself after each sax event.
Example quick? Create a global case object in your handler, and 
At each start element check if it is a <case> or an <assigned> or
something else..
If it is a case, instantiate a new Case(), otherwise call setAssigned(),
setSubject etc....

Regards	
	marco

-----Original Message-----
From: ssrinivasrao@worldbank.org [mailto:ssrinivasrao@worldbank.org] 
Sent: 23 February 2004 10:07
To: Struts-User@jakarta.apache.org
Subject: urgent please -- XML document reading/parsing through SAX for
the given snippet.

Hi,

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
information).

<case id="RMA-1234">
      <assigned-to>Abrao I. Grynglas</assigned-to>
      <subject>This is the subject of email</subject>
      <referred-to>Yes</referred-to>
      <status>Document Open</status>
      <date>16-Sep-03</date>
      <priority>High</priority>
</case>

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();
                  Cases.add(thisCase);
            }
      }
      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: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Mime
View raw message