OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

Using SAX API

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Code Snippets
View previous topic :: View next topic  
Author Message
nicky-river
Newbie
Newbie


Joined: 21 Dec 2007
Posts: 3

PostPosted: Fri Dec 21, 2007 9:07 pm    Post subject: Using SAX API Reply with quote

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
View user's profile Send private message
Sliderule
Super User
Super User


Joined: 29 May 2004
Posts: 2474
Location: 3rd Rock From The Sun

PostPosted: Fri Dec 21, 2007 10:34 pm    Post subject: Reply with quote

nicky-river:

Please look at the following references:I hope this helps, please be sure to let me / us know.

Sliderule
Back to top
View user's profile Send private message
SergeM
Super User
Super User


Joined: 09 Sep 2003
Posts: 3211
Location: Troyes France

PostPosted: Sun Dec 23, 2007 12:44 pm    Post subject: Reply with quote

See also :
Parsing a XML-pipe ? (OOoBasic+SAX) http://www.oooforum.org/forum/viewtopic.phtml?t=43329
XML DannyB :Using UNO's Xml sax parser via the API http://www.oooforum.org/forum/viewtopic.phtml?t=4907
_________________
Linux & Windows OOo3.0
UNO & C++ : WIKI
http://wiki.services.openoffice.org/wiki/Using_Cpp_with_the_OOo_SDK
In French
http://wiki.services.openoffice.org/wiki/Documentation/FR/Cpp_Guide
Back to top
View user's profile Send private message Visit poster's website
nicky-river
Newbie
Newbie


Joined: 21 Dec 2007
Posts: 3

PostPosted: Thu Dec 27, 2007 8:35 pm    Post subject: Thanks for the help!!! Reply with quote

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
View user's profile Send private message
Sliderule
Super User
Super User


Joined: 29 May 2004
Posts: 2474
Location: 3rd Rock From The Sun

PostPosted: Thu Dec 27, 2007 8:47 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Code Snippets All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group