Results 1 to 4 of 4

Thread: Retrieving data from an XML file for use in a servlet

  1. #1
    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.

  2. #2
    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.*;

  3. #3
    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).

  4. #4
    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();
    
        }
    }

Similar Threads

  1. Replies: 2
    Last Post: 14-03-2012, 03:29 PM
  2. Replies: 4
    Last Post: 21-02-2012, 06:14 PM
  3. Replies: 5
    Last Post: 12-08-2010, 11:36 PM
  4. How to retrieving data in a file from Creating form
    By MARCIA in forum Software Development
    Replies: 3
    Last Post: 10-03-2009, 11:18 AM
  5. Retrieving data from damaged HDD
    By Adit in forum Hardware Peripherals
    Replies: 2
    Last Post: 22-11-2008, 05:23 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,710,843,335.14204 seconds with 16 queries