org.exolab.castor.xml.dtd

Class Converter

public class Converter extends Object

Class containing static top-level methods to parse and convert XML DTD documents to corresponding XML Schema documents. Also contains simple command line interface to read an XML DTD file and create corresponding XML Schema object.

Version: $Revision: 1.2 $ $Date: 2003/03/03 09:57:18 $

Author: Alexander Totok

Method Summary
static AttributeDeclconvertAttribute(Attribute dtdAttribute, Schema schema)
Convert DTD Attribute declaration to Schema Attribute Declaration.
static ParticleconvertContentParticle(ContentParticle dtdContent, Schema schema)
Method to convert {@link org.exolab.castor.xml.dtd.ContentParticle ContentParticle} object, used to implement element content in the DTD object model, to the corresponding object in the Schema object model: either {@link org.exolab.castor.xml.schema.Group Group} or {@link org.exolab.castor.xml.schema.ElementDecl ElementDecl}.
static ElementDeclconvertDTDElementToSchemaElement(Element dtdElement, Schema schema)
Convert DTD Element declaration to Schema Element Declaration.
static SchemaconvertDTDObjectToSchemaObject(DTDdocument dtd)
Convert DTD document object to corresponding Schema object.
static voidconvertDTDtoSchema(Reader reader, Writer writer)
Convert DTD document to corresponding XML Schema document.
static voidmain(String[] args)
Simple command line interface to read an XML DTD file and create corresponding XML Schema file.
static voidmarshalSchema(Schema schema, Writer writer)
Marshals XML Schema to output char stream.
static DTDdocumentparseDTD(Reader reader)
Parses text of a DTD document and returns corresponding DTD document object.

Method Detail

convertAttribute

public static AttributeDecl convertAttribute(Attribute dtdAttribute, Schema schema)
Convert DTD Attribute declaration to Schema Attribute Declaration.

Parameters: dtdAttribute DTD Attribute declaration. schema Schema owning Element of this Attribute.

Returns: corresponding Schema Attribute declaration.

Throws: DTDException if the input DTD Attribute Declaration is malformed.

convertContentParticle

public static Particle convertContentParticle(ContentParticle dtdContent, Schema schema)
Method to convert {@link org.exolab.castor.xml.dtd.ContentParticle ContentParticle} object, used to implement element content in the DTD object model, to the corresponding object in the Schema object model: either {@link org.exolab.castor.xml.schema.Group Group} or {@link org.exolab.castor.xml.schema.ElementDecl ElementDecl}.

Parameters: dtdContent input {@link org.exolab.castor.xml.dtd.ContentParticle ContentParticle} object.

Returns: object returned is an instance of either {@link org.exolab.castor.xml.schema.Group Group} class or {@link org.exolab.castor.xml.schema.ElementDecl ElementDecl} class.

Throws: DTDException if the input ContentParticle is malformed. SchemaException if unable to construct return content object from a given ContentParticle

convertDTDElementToSchemaElement

public static ElementDecl convertDTDElementToSchemaElement(Element dtdElement, Schema schema)
Convert DTD Element declaration to Schema Element Declaration.

Parameters: dtdElement DTD Element declaration. schema Schema owning Element declaration.

Returns: corresponding Schema Element declaration.

Throws: DTDException if the input DTD Element Declaration is malformed. SchemaException if unable to construct return {@link org.exolab.castor.xml.schema.ElementDecl ElementDecl} object from the input DTD {@link org.exolab.castor.xml.dtd.Element Element} object.

convertDTDObjectToSchemaObject

public static Schema convertDTDObjectToSchemaObject(DTDdocument dtd)
Convert DTD document object to corresponding Schema object.

Parameters: dtd input XML DTD document object.

Returns: corresponding XML Schema object.

Throws: DTDException if the input DTD document is malformed. SchemaException if Schema object can not be created.

convertDTDtoSchema

public static void convertDTDtoSchema(Reader reader, Writer writer)
Convert DTD document to corresponding XML Schema document.

Parameters: reader reader of the input DTD document. writer writer to the output Schema document.

Throws: DTDException if the DTD document is syntactically or semanticly not correct. SchemaException if Schema object can not be created. IOException if there is an I/O problem with the reader or writer. SAXException if an error occured during schema object marshalling.

main

public static void main(String[] args)
Simple command line interface to read an XML DTD file and create corresponding XML Schema file. Usage:

 java org.exolab.castor.xml.dtd.Converter  dtd_file xsd_file [character_encoding]



 dtd_file: name of the input DTD file

 xsd_file: name of the output Schema file

 character_encoding: name of the character encoding,

            if not specified, ASCII is chosen
Help message is provided.

Throws: DTDException if the input DTD document is malformed. SchemaException if Schema object can not be created. SAXException if an error occured during marshalling of schema object constructed from the DTD document.

marshalSchema

public static void marshalSchema(Schema schema, Writer writer)
Marshals XML Schema to output char stream.

Parameters: schema XML Schema object to marshal. writer output char stream to marshal Schema to.

Throws: IOException if there is an I/O problem with the writer. SAXException if an error occured during schema marshalling.

parseDTD

public static DTDdocument parseDTD(Reader reader)
Parses text of a DTD document and returns corresponding DTD document object. It is left to constructor of the reader to set up character encoding correctly. This means that method read of the reader is used to get next character, assuming it returns appropriate values.

Parameters: reader input char stream reader. It is recommended to use class {@link java.io.InputStreamReader java.io.InputStreamReader} as a reader, which allows to set desired character encoding.

Returns: DTD document object corresponding to the input text of a DTD document.

Throws: DTDException if the DTD document is syntactically or semanticly not correct.

Intalio Inc. (C) 1999-2003. All rights reserved http://www.intalio.com