File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes XML and Related Technologies and the fly likes SAX and characters() -method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "SAX and characters() -method" Watch "SAX and characters() -method" New topic
Author

SAX and characters() -method

John Sisco
Greenhorn

Joined: Nov 22, 2004
Posts: 8
Hello,

Still quite new to SAX-parsing and would appreciate any help on this matter.

Ok, I have the characters-method to capture the elements I need but have problem when trying to save them to an dynamic array for later use.



If I try to save them to an array in the above if-clause, it just shows null when I'm trying to read the array somewhere outside characters()-method. At the moment I've come around this by writing the results to a .txt-file (yeah, how stupid) and retrieving the results from there when needed.



Above is the method where the actual parsing is invoked.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12761
    
    5
If I try to save them to an array in the above if-clause,

If by that you mean you are trying to save the char[] reference, thats the wrong approach. That char[] is the buffer the SAX parser is using!
A typical approach is to use a StringBuffer and the append( char[], int offset, int len ) method.
Create the StringBuffer when the startElement for the element you want occurs. Recall that the SAX parser may call characters one or many times before the end of the element is reached.
Bill
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: SAX and characters() -method
 
Similar Threads
Entities in attribute values issue in Sax parser
JList in JScrollPane
How can I convert the xml to a string?
Entity Resolver not working fine while unmarshalling using JAXB ?
Can any one help me