> List of tutorials

Table of contents for this tutorial

Fat-Client-Development - Base-Class to read a file with a XML-structure

* For this document and all references (links) please obey the hints and regulations concerning copyright, disclaimer and trademarks.

  • The owner of this web-site (www.javascout.biz) is not responsible for the content of web-sites linked within this document or other documents of www.javascout.biz.

  • If this document or other documents of this web-site (www.javascout.biz) infringes your rights or you think that rights of others (third parties) are infringed, please inform the author.
    An e-mail can be sent by clicking onto the 'hungry mailbox' in the upper right corner.

Last revision of this document:
2006-05-05

This is document contains the code for Class JSBS_XML_Base.
For easy 'cut and paste' ;-)

package js_base.xml;

import org.jdom.*;
import org.jdom.input.*;
/**
 
*
 * @author
kurt@javascout.biz
 * @date 2006-05-19
 *
 * @description
 *  Class with a complete XML-document (represented by the RootElement)
 *  and a method to read a file containing a XML-structure.
 *  This class can be inherited by other classes to read data out of a XML-structure.
 
*
 * @change-log
 * when         who               why
 * --------------------------------------------------------
 *
 */

public class JSBS_XML_Base implements JSBS_XML_Constants {
/*
 * RootElement as entry-point to the XML-structure. */
    protected Element
XML_RootElement;
/*
 * Status code to signal results (see interface JSBS_XML_Constants)
 * of methods to the caller. */
    public int StatusCode = CONST_UNKNOWN_ERROR;
/*
 * -------------------------------
 * Constructor of the class */
    public JSBS_XML_Base() {
    }
/*
 * */
    protected void readXMLFile(String parmFileName) {
/* Method to read a file and create the XML-document within the memory */
        try {
/* Use the SAX-method to open the file */
          SAXBuilder parser = new SAXBuilder();
/* Parse the file into a document according to the Document Object Model (DOM) */
          Document document = parser.build(parmFileName);
/* Retrieve the root-element from the DOM-document */
          XML_RootElement = document.getRootElement();
/* File read and parsed without an error - reflect this in the status */
          StatusCode = CONST_OK;
        
}

        catch (JDOMException e) {
          StatusCode = CONST_NOT_WELL_FORMED;
        
}

        catch (Exception e) {
          StatusCode = CONST_UNKNOWN_ERROR;
        
}

    }
}