| View previous topic :: View next topic |
| Author |
Message |
nicky-river Newbie

Joined: 21 Dec 2007 Posts: 3
|
Posted: Fri Dec 21, 2007 9:07 pm Post subject: Using SAX API |
|
|
Hi everyone,
I am developing an application in which information of books is exchanged between the organization & clients as XML documents. I need to process these documents before sending them to the clients. I wish to process these documents using SAX API. I prefer to use SAX API because it is suitable for processing large XML documents as it uses less memory to parse the XML document. In this regard, I would be extremly grateful if anyone could provide me with some information regarding how to use SAX API for this application or even a small code snippet could be helpful for me to develop this application. Thanking all in anticipation. |
|
| Back to top |
|
 |
Sliderule Super User


Joined: 29 May 2004 Posts: 2474 Location: 3rd Rock From The Sun
|
Posted: Fri Dec 21, 2007 10:34 pm Post subject: |
|
|
nicky-river:
Please look at the following references:I hope this helps, please be sure to let me / us know.
Sliderule |
|
| Back to top |
|
 |
SergeM Super User

Joined: 09 Sep 2003 Posts: 3211 Location: Troyes France
|
|
| Back to top |
|
 |
nicky-river Newbie

Joined: 21 Dec 2007 Posts: 3
|
Posted: Thu Dec 27, 2007 8:35 pm Post subject: Thanks for the help!!! |
|
|
Hi sliderule,
Thanks for sending me these documents. it has definitely helped me in my application. I have tried to implement it in my application. I have provided my XML document with this message as well as a code snippet of the SAX parser that I have used for this application.
| Code: |
<?xml version="1.0" encoding="UTF-8"?>
<BookInfo>
<Book>
<BookName>Don - The Chase Begins Again</BookName>
<BookPrice>Rs. 500 </BookPrice>
<BookAuthor>Farhan Akhtar</BookAuthor>
</Book>
<Book>
<BookName>Quantitative Aptitude</BookName>
<BookPrice>Rs. 380 </BookPrice>
<BookAuthor>R.S Aggarwal</BookAuthor>
</Book>
</BookInfo>
|
The SAX code snippet is as given below
| Code: |
import java.io.*;
import org.xml.sax.*;
import org.xml.sax.helpers.DefaultHandler;
import javax.xml.parsers.SAXParserFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
public class DisplayBookSax extends DefaultHandler
{
static private Writer writerOut;
StringBuffer stringBuffer;
public static void main(String fileName[])
{
if(fileName.length!=1)
{
System.err.println("Usage: cmd filename");
System.exit(1);
}
DefaultHandler defaultHandler = new DisplayBookSax();
SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
try
{
writerOut = new OutputStreamWriter(System.out,"UTF-8");
SAXParser Sax_Parser = saxParserFactory.newSAXParser();
Sax_Parser.parse(new File(fileName[0]), defaultHandler);
}
catch(Throwable thr)
{
thr.printStackTrace();
}
System.exit(0);
}
public void startDocument() throws SAXException
{
IOHandler("<?xml version = '1.0' encoding = 'UTF-8'?>");
newLine();
}
public void endDocument() throws SAXException
{
try
{
newLine();
writerOut.flush();
}
catch(IOException e)
{
throw new SAXException("I/O error", e);
}
}
|
Please give me a few details on how to continue from endDocument(). Thanking all in anticipation. |
|
| Back to top |
|
 |
Sliderule Super User


Joined: 29 May 2004 Posts: 2474 Location: 3rd Rock From The Sun
|
Posted: Thu Dec 27, 2007 8:47 pm Post subject: |
|
|
nicky-river:
You asked: | nicky-river wrote: | | Please give me a few details on how to continue from endDocument(). Thanking all in anticipation. |
Please understand, I know nothing about this . . . but . . . did a search in the forums that provided the above links.
Now, I do have a suggestion, since I cannot help . . . I suggest you 'repost' you last question in the OpenOffice.org Macros and API forum . . . I suspect that the folks in that forum would be of more help.
Sliderule
Thanks to add [Solved] in your first post title (edit button) if your issue has been fixed / resolved. |
|
| Back to top |
|
 |
|