tribble.xml.schema
Class XmlData

java.lang.Object
  extended bytribble.xml.schema.XmlData

public class XmlData
extends java.lang.Object

Methods to convert a Java class to an XML data document.

Example

Consider the following class:

    public class CustOrder
    {
        public String       m_custName =    "Acme Rockets & Fun, Inc.";
        public int          m_p_o_number =  100627;
        public int          m_cost =        14995;
        public String       m_address =     "1450 Desert Plain";
        public Integer      m_count =       new Integer(10);
        private int         m_refId =       7528;
        transient int       m_addln =       149;
        public Address      m_addr =
            new Address("123 Anywhere St", "Boston", "MA", "02134");

        public static class Address
        {
            public String   m_street;
            public String   m_city;
            public String   m_state;
            public String   m_zip;
            ...
        }
    } 

This class object would be written as the following XML document:

    <CustOrder>
      <custName>Acme Rockets &amp; Fun, Inc.</custName>
      <p-o-number>100627</p-o-number>
      <cost>14995</cost>
      <address>1450 Desert Plain</address>
      <count>10</count>
      <addr>
        <street>123 Anywhere St</street>
        <city>Boston</city>
        <state>MA</state>
        <zip>02134</zip>
      </addr>
    </CustOrder> 

Since:
2003-07-09
Version:
$Revision: 1.16 $ $Date: 2003/08/24 21:25:18 $
Author:
David R. Tribble (david@tribble.com).
Copyright ©2003 by David R. Tribble, all rights reserved.

PROPRIETARY SOURCE CODE, RESTRICTED TO USE UNDER LICENSE.

Method Summary
static void main(java.lang.String[] args)
          Test driver for this class.
static void writeObjectXml(java.lang.Object obj, java.io.OutputStream out)
          Write the contents of an object as an XML data document.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
Test driver for this class.

Usage

java tribble.xml.schema.XmlData [-o out.xml] pkg.class

Loads the class named pkg.class (which should be located somewhere in the CLASSPATH), then creates a new object instance of that type, then writes its contents as an XML data document to the file out.xml, or to the standard output if no output file is specified.

Parameters:
args - Command line arguments.
Throws:
java.lang.Exception - Thrown if an I/O (write) error occurs, or if class pkg.class could not be loaded, or if an object of that type could not be instantiated.
Since:
1.1, 2003-07-12

writeObjectXml

public static void writeObjectXml(java.lang.Object obj,
                                  java.io.OutputStream out)
                           throws java.io.IOException,
                                  java.lang.IllegalAccessException
Write the contents of an object as an XML data document.

See the example above for more details.

Parameters:
obj - Object to write.
out - Output stream to write the XML document to. If this is null, no action is performed. For efficiency, it is recommended that this object be a type derived from java.io.PrintStream.
Throws:
java.io.IOException - Thrown if an I/O (write) error occurs.
java.lang.IllegalArgumentException - (unchecked) Thrown if obj cannot be written as XML.
java.lang.IllegalAccessException - Thrown if obj or one of its members cannot be accessed.
java.lang.NullPointerException - (unchecked) Thrown if obj is null.
Since:
1.1, 2003-07-09