xml2class
XML data structures

xml2class
Class XMLFile

java.lang.Object
  |
  +--xml2class.XMLFile

public class XMLFile
extends java.lang.Object

An auxiliary class for XML file handling. It allows even more facilitated file parsing and saving in several different parameter combinations. For best parsing control, it is recommended to implement these methods in your own code.

Author:
Simon Bünzli, zeniko@gmx.ch
See Also:
XML2ClassParser, X2cTools, X2cException

Constructor Summary
XMLFile()
           
 
Method Summary
static void main(java.lang.String[] args)
          Allows to parse from the command line a XML file, which should contain also instructions on how to proceed when the parsing process is complete. Syntax: XMLFile [directory/filename.xml] [package.name] [verbose].
static java.lang.Object parse(java.lang.String filename, java.lang.String classRoot)
          Parse directly a whole structure from a file.
static java.lang.Object parse(java.lang.String filename, java.lang.String[] classRoots, boolean verbose, boolean resource)
          Parse directly a whole structure from a (resource) file.
static java.lang.Object parse(java.lang.String filename, java.lang.String classRoot, boolean verbose)
          Parse directly a whole structure from a file.
static java.lang.Object parseResource(java.lang.String filename, java.lang.String classRoot)
          Parse directly a whole structure from a resource file.
static java.lang.Object parseResource(java.lang.String filename, java.lang.String classRoot, boolean verbose)
          Parse directly a whole structure from a resource file.
static void save(java.lang.Object root, java.lang.String filename)
          Save the data structure - given its root element - back to a file.
static void save(java.lang.Object root, java.lang.String filename, java.lang.String doctype)
          Save the data structure - given its root element - back to a file.
static void save(java.lang.String xmlString, java.lang.String filename, java.lang.String doctype, boolean resource)
          Save the data structure - given its XML representation - back to a (resource) file.
static void saveResource(java.lang.Object root, java.lang.String filename)
          Save the data structure - given its root element - back to a resource file.
static void saveResource(java.lang.Object root, java.lang.String filename, java.lang.String doctype)
          Save the data structure - given its root element - back to a resource file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XMLFile

public XMLFile()
Method Detail

parse

public static java.lang.Object parse(java.lang.String filename,
                                     java.lang.String classRoot)
                              throws X2cException
Parse directly a whole structure from a file.
Parameters:
filename - the XML file to be parsed (incl. relative path).
classRoot - where the respective class files are (relative paths, separated by spaces).
Returns:
the data structure's root element.
Throws:
X2cException - will be thrown at any exceptional situation.

parse

public static java.lang.Object parse(java.lang.String filename,
                                     java.lang.String classRoot,
                                     boolean verbose)
                              throws X2cException
Parse directly a whole structure from a file.
Parameters:
filename - the XML file to be parsed (incl. relative path).
classRoot - where the respective class files are (relative paths, separated by spaces).
verbose - should the parser be in verbose mode (verbose output to System.out)?
Returns:
the data structure's root element.
Throws:
X2cException - will be thrown at any exceptional situation.

parseResource

public static java.lang.Object parseResource(java.lang.String filename,
                                             java.lang.String classRoot)
                                      throws X2cException
Parse directly a whole structure from a resource file.
Parameters:
filename - the XML file to be parsed (incl. relative path).
classRoot - where the respective class files are (relative paths, separated by spaces).
Returns:
the data structure's root element.
Throws:
X2cException - will be thrown at any exceptional situation.

parseResource

public static java.lang.Object parseResource(java.lang.String filename,
                                             java.lang.String classRoot,
                                             boolean verbose)
                                      throws X2cException
Parse directly a whole structure from a resource file.
Parameters:
filename - the XML file to be parsed (incl. relative path).
classRoot - where the respective class files are (relative paths, separated by spaces).
verbose - should the parser be in verbose mode (verbose output to System.out)?
Returns:
the data structure's root element.
Throws:
X2cException - will be thrown at any exceptional situation.

parse

public static java.lang.Object parse(java.lang.String filename,
                                     java.lang.String[] classRoots,
                                     boolean verbose,
                                     boolean resource)
                              throws X2cException
Parse directly a whole structure from a (resource) file.
Parameters:
filename - the XML file to be parsed (incl. relative path).
classRoots - where the respective class files are (relative paths).
verbose - should the parser be in verbose mode (verbose output to System.out)?
resource - is the indicated file available as resource file?
Returns:
the data structure's root element.
Throws:
X2cException - will be thrown at any exceptional situation.

save

public static void save(java.lang.Object root,
                        java.lang.String filename)
                 throws X2cOutputException
Save the data structure - given its root element - back to a file. Beware: The structure's elements must support toXMLString()!
Parameters:
root - the data structure's root element.
filename - where the structure should be saved to (incl. relative path).
Throws:
X2cOutputException - will be thrown for any exception.

save

public static void save(java.lang.Object root,
                        java.lang.String filename,
                        java.lang.String doctype)
                 throws X2cOutputException
Save the data structure - given its root element - back to a file. Additionally you may put some DOCTYPE information ( [rootElementName] SYSTEM "[DTD file name]"). Beware: The structure's elements must support toXMLString()!
Parameters:
root - the data structure's root element.
filename - where the structure should be saved to (incl. relative path).
doctype - a doctype definition string.
Throws:
X2cOutputException - will be thrown for any exception.

saveResource

public static void saveResource(java.lang.Object root,
                                java.lang.String filename)
                         throws X2cOutputException
Save the data structure - given its root element - back to a resource file. Beware: The structure's elements must support toXMLString()! Important note: this method does not seem to work under JDK1.1!
Parameters:
root - the data structure's root element.
filename - where the structure should be saved to (incl. relative path).
Throws:
X2cOutputException - will be thrown for any exception.

saveResource

public static void saveResource(java.lang.Object root,
                                java.lang.String filename,
                                java.lang.String doctype)
                         throws X2cOutputException
Save the data structure - given its root element - back to a resource file. Additionally you may put some DOCTYPE information ( [rootElementName] SYSTEM "[DTD file name]"). Beware: The structure's elements must support toXMLString()! Important note: this method does not seem to work under JDK1.1!
Parameters:
root - the data structure's root element.
filename - where the structure should be saved to (incl. relative path).
doctype - a doctype definition string.
Throws:
X2cOutputException - will be thrown for any exception.

save

public static void save(java.lang.String xmlString,
                        java.lang.String filename,
                        java.lang.String doctype,
                        boolean resource)
                 throws X2cOutputException
Save the data structure - given its XML representation - back to a (resource) file. Additionally you may put some DOCTYPE information ( [rootElementName] SYSTEM "[DTD file name]"). Use this method, if you do the toXML conversion outside the data structure. Important note: saving to a resource file does not seem to work under JDK1.1!
Parameters:
xmlString - the data structure's XML representation.
filename - where the structure should be saved to (incl. relative path).
doctype - a doctype definition string.
resource - is the indicated file a resource file?
Throws:
X2cOutputException - will be thrown for any exception.

main

public static void main(java.lang.String[] args)
                 throws X2cException

Allows to parse from the command line a XML file, which should contain also instructions on how to proceed when the parsing process is complete.

Syntax: XMLFile [directory/filename.xml] [package.name] [verbose].


xml2class
XML data structures

Copyleft 2001 by Simon Bünzli, zeniko@gmx.ch