daily pastebin goal
77%
SHARE
TWEET

Untitled

a guest Sep 14th, 2018 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. SAX callback not updating global stringbuffer
  2. public class SAXXMLParser extends DefaultHandler
  3. {
  4.     SAXParserFactory factory;
  5. SAXXMLParser dh;
  6. SAXParser sax;
  7. StringBuffer accumulator;
  8. String remember = "";
  9.  
  10. public String saxParse( String msgToParse, String uriPathExpression )
  11.         throws SAXException, IOException, ParserConfigurationException
  12. {
  13.     System.out.println( "saxParse" );
  14.  
  15.     factory = SAXParserFactory.newInstance();
  16.     sax = factory.newSAXParser();
  17.     dh = new SAXXMLParser();
  18.     InputStream is = new ByteArrayInputStream( msgToParse.getBytes() );
  19.     sax.parse( is , dh );
  20.  
  21.     System.err.println( remember );
  22.     return remember;
  23. }
  24.  
  25. public void startElement( String uri, String localName, String elementName,           Attributes attrs )
  26. {
  27.     accumulator.setLength(0);
  28. }
  29.  
  30. public void endElement( String uri, String name, String qName )
  31. {
  32.     System.out.println( qName );
  33.     if( qName.equalsIgnoreCase( "my element" ) )
  34.     {
  35.         remember = accumulator.toString();
  36.     }
  37. }
  38.  
  39. public void characters( char[] ch, int start, int len )
  40. {
  41.     accumulator.append( ch, start, len );
  42. }
  43.  
  44. public void startDocument()
  45. {
  46.     accumulator = new StringBuffer();
  47. }
  48. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top