Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 12-05-2009
Member
 
Join Date: Apr 2009
Posts: 78
Retrieving data from an XML file for use in a servlet

I need to develop servlet and while do that I want to retrieve data from the XML file, this will be because i have most of my data in XML format which i have practiced for manipulation.

My question is that what classes I need to import to achieve this, and what kind of servlet coding i need to do in order to retrieve and use the data in XML file?

thanks for your suggestions.
Reply With Quote
  #2  
Old 12-05-2009
Member
 
Join Date: Oct 2008
Posts: 167
Re: Retrieving data from an XML file for use in a servlet

First a fall you need to Import following packages:

mport javax.xml.parsers.*;
import org.xml.sax.*;
import org.xml.sax.helpers.*;
import org.w3c.dom.*;
import java.io.*;
Reply With Quote
  #3  
Old 12-05-2009
Member
 
Join Date: Jan 2009
Posts: 143
Re: Retrieving data from an XML file for use in a servlet

You need to run the page on the same domain/port number as the data source. Whichever XML file you are having try to open the data XML in the Internet Explorer window. If nothing helps, then data._http.statusText should have the error message (see MSXML2.XMLHTTP docs).
Reply With Quote
  #4  
Old 12-05-2009
Member
 
Join Date: Apr 2009
Posts: 26
Re: Retrieving data from an XML file for use in a servlet

I am newbie to the forum and the answer i am providing is from reading blog content but not sure whether this will helps you this is what i think would be the answer for your problem, you may place your file anywhere on the server where you deploy the application. If security permissions allows then you should be able to reference it by an absolute file path. Here is an example of a small Java service to read a logfile and return its contents in the form of a string:

Code:
package com.wavemaker;
import java.io.*;

public class LogReader {

    public String readLog (String fileName) {

        StringBuffer sb = new StringBuffer();

        try {
            BufferedReader is = new BufferedReader(new FileReader(fileName));

            char[] b = new char[8192];
            int n;

            // Read a block. If it gets any chars, append them.
            while ((n = is.read(b)) > 0) {sb.append(b, 0, n);}
            is.close();

        } catch (Exception ex) {
            throw new RuntimeException(ex);
        }
        return sb.toString();

    }
}
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Retrieving data from an XML file for use in a servlet"
Thread Thread Starter Forum Replies Last Post
Need help in retrieving and posting data to the database (ms access) from C#.net KJo Software Development 2 14-03-2012 03:29 PM
Converting data input from Word doc and excel file into a pdf file Adi.Das Windows Software 4 21-02-2012 06:14 PM
Encrypting File System (EFS) encrypted file data corrupt after shutdown and restart Abhik Windows Software 5 12-08-2010 11:36 PM
How to retrieving data in a file from Creating form MARCIA Software Development 3 10-03-2009 11:18 AM
Retrieving data from damaged HDD Adit Hardware Peripherals 2 22-11-2008 05:23 PM


All times are GMT +5.5. The time now is 06:55 AM.