|
Last
revision of this document: |
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;
}
}
}