Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7068953
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:23:12+00:00 2026-05-28T05:23:12+00:00

I am using SAX Parser to parse the XML file over the network. While

  • 0

I am using SAX Parser to parse the XML file over the network.
While parsing I want to add data into database so for that I use INSERT query to add the data. But each insert takes: 10 – 15 ms and I have almost 150 records which almost takes 130 seconds to parse and insert.
I have tried to wrap around the insert query in transactions but it still gives me same time. I have attached my code. I am not sure if I am parsing it correctly or my insert transaction is wrong?

XMLHandler.java

public class XMLHandler extends DefaultHandler {

private static boolean inKey = false;
private static boolean inCode = false;
private static boolean inTitle = false;
private static boolean inType = false;
private static boolean inRoom = false;
private static boolean inDescription = false;
private static boolean inStart = false;

private List List = new List();

public void startElement(String uri, String name, String qName,
    Attributes atts) {

if (name.trim().equals("key"))
    inKey = true;
else if (name.trim().equals("code"))
    inCode = true;
else if (name.trim().equals("title"))
    inTitle = true;
else if (name.trim().equals("type"))
    inType = true;
else if (name.trim().equals("room"))
    inRoom = true;
else if (name.trim().equals("description"))
    inDescription = true;
else if (name.trim().equals("start"))
    inClassStart = true;

}

public void endElement(String uri, String name, String qName)
    throws SAXException {

if (name.trim().equals("key"))
    inKey = false;
else if (name.trim().equals("code"))
    inCode = false;
else if (name.trim().equals("title"))
    inTitle = false;
else if (name.trim().equals("type"))
    inType = false;
else if (name.trim().equals("room"))
    inRoom = false;
else if (name.trim().equals("description"))
    inDescription = false;
else if (name.trim().equals("start"))
    inClassStart = false;
}

public void characters(char ch[], int start, int length) {

String chars = (new String(ch).substring(start, start + length));

try {
    if(inKey)
           List.key = chars;
    if(inCode)
       List.code = chars;
    if(inTitle)
        List.title = chars;
    if(inType)
        List.type = chars;
    if(inRoom)
        List.room = chars;
    if(inDescription)
        List.description = chars;
    if(inStart)
        List.start = chars;

    DB.insertFeed(List.key, List.code, List.title, List.type, List.room, List.description, List.start);

} catch (Exception e) {
    Log.e("NewsDroid", e.toString());
}

}

DatabaseManager.java

 public void insertFeed( String key, String code, String title, String type, String room, String desc,String start) {


    db.beginTransaction();
        try{
            String sql = "INSERT OR REPLACE INTO " + TEST+  "(KEY,CODE,TITLE, TYPE ,ROOM , DESCRIPTION, START) VALUES" + "(?,?,?,?,?,?,?);";
             Object [] bindArgs = new Object[]{key,code,title,type,room, desc,start};
          db.execSQL(sql, bindArgs);    
             db.setTransactionSuccessful();
}
    catch (SQLException e){}

    finally{

        db.endTransaction();
    }
 }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T05:23:12+00:00Added an answer on May 28, 2026 at 5:23 am

    You are inserting one row each time and might be doing db.open() and db.close() each time.
    Instead of this try to use the “InsertHelper”.
    A crude example to use it shown below:

    private void insertTweetSourcesInBulk(ArrayList tweetSources, boolean replace) {
    InsertHelper ih = new InsertHelper(db, TABLE_NAME_TWEET_SOURCE);

        final int idIndex = ih.getColumnIndex(Audio._ID);
        final int sequenceNumIndex = ih.getColumnIndex(TweetSource.SEQUENCE_NUM);
        final int thumbnailUrlIndex = ih.getColumnIndex(TweetSource.THUMBNAIL_URL);
        final int titleIndex = ih.getColumnIndex(TweetSource.TITLE);
    
        for (TweetSource source : tweetSources) {
            Logger.log(TAG, "Inserting id: " + source.getId());
    
            if (replace) {
                ih.prepareForReplace();
            } else {
                ih.prepareForInsert();
            }
    
            ih.bind(idIndex, Integer.parseInt(source.getId()));
            ih.bind(sequenceNumIndex, Float.parseFloat(source.getSequenceNum()));
            ih.bind(thumbnailUrlIndex, source.getThumbnailUrl());
            ih.bind(titleIndex, source.getTitle());
    
            ih.execute();
        }
    
        ih.close();
    }
    

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem with using the SAX parser to parse a XML file.
I have student.xml file and am parsing this file using SAX Parser and now
i try to parse an rdf file using android.sax and android.utils.Xml methods. My parser
I want to extract attributes from an xml file using Sax Parser I am
hi friends i'm using Sax parser for parsing my xml file which i recieve
I'm parsing an HTML file into a well-formed XML document using NekoHTML parser. However
I have been using a SAX parser for a while now to get data
I am trying to parse an XML file using the SAX interface of libxml2
I am using SAX to parse an XML file I'm pulling from the web.
I am trying to parse XML in Perl using XML::SAX parser . My query

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.