XML to Java SAX emitter compiler

Discussion in 'XML' started by Henri Sivonen, Jan 6, 2005.

  1. I am generating XML by emitting SAX events programmatically from Java.
    However, there's a lot of boilerplate markup, so being able to generate
    code from XML would be nice.

    Is there a tool that would take an XML file like this

    <?args org.xml.sax.ContentHandler ch, com.example.Foo foo ?>
    <baz xmlns="http://example.com/fooml/">
    <?code foo.bar(ch); ?>
    </baz>

    and would generate a Java class like this

    public class GeneratedEmitter {
    public static void emit(org.xml.sax.ContentHandler ch,
    com.example.Foo foo) throws SAXException {
    ch.startDocument();
    ch.startElement("http://example.com/fooml/", "baz", "baz", new
    AttributesImpl());
    foo.bar(ch);
    ch.endElement("http://example.com/fooml/", "baz", "baz");
    ch.endDocument();
    }
    }

    ?

    --
    Henri Sivonen

    http://iki.fi/hsivonen/
     
    Henri Sivonen, Jan 6, 2005
    #1
    1. Advertising

  2. Henri Sivonen

    Ira Baxter Guest

    "Henri Sivonen" <> wrote in message
    news:...
    > I am generating XML by emitting SAX events programmatically from Java.
    > However, there's a lot of boilerplate markup, so being able to generate
    > code from XML would be nice.
    >
    > Is there a tool that would take an XML file like this
    >
    > <?args org.xml.sax.ContentHandler ch, com.example.Foo foo ?>
    > <baz xmlns="http://example.com/fooml/">
    > <?code foo.bar(ch); ?>
    > </baz>
    >
    > and would generate a Java class like this
    >
    > public class GeneratedEmitter {
    > public static void emit(org.xml.sax.ContentHandler ch,
    > com.example.Foo foo) throws SAXException {
    > ch.startDocument();
    > ch.startElement("http://example.com/fooml/", "baz", "baz", new
    > AttributesImpl());
    > foo.bar(ch);
    > ch.endElement("http://example.com/fooml/", "baz", "baz");
    > ch.endDocument();


    Code generation from XML is a popular topic.

    Since many XML documents represent trees,
    doing a classic on-the-fly code generator by
    tree walk is one way to do it. XSLT
    can often be used to do this.

    Other ways are to build ad-hoc code generators
    in your favorite programming language by
    making calls on a DOM to get at the XML data.

    A tool that accepts source-to-source transformations,
    that could do XML to Java generation directly
    is the DMS Software Reengineering Toolkit.
    See http://www.semanticdesigns.com/Products/DMS/DMSToolkit.html.


    --
    Ira D. Baxter, Ph.D., CTO 512-250-1018
    Semantic Designs, Inc. www.semdesigns.com
     
    Ira Baxter, Jan 15, 2005
    #2
    1. Advertising

  3. In article <>,
    "Ira Baxter" <> wrote:

    > "Henri Sivonen" <> wrote in message
    > news:...
    > > I am generating XML by emitting SAX events programmatically from Java.
    > > However, there's a lot of boilerplate markup, so being able to generate
    > > code from XML would be nice.


    > Since many XML documents represent trees,
    > doing a classic on-the-fly code generator by
    > tree walk is one way to do it. XSLT
    > can often be used to do this.
    >
    > Other ways are to build ad-hoc code generators
    > in your favorite programming language by
    > making calls on a DOM to get at the XML data.
    >
    > A tool that accepts source-to-source transformations,
    > that could do XML to Java generation directly
    > is the DMS Software Reengineering Toolkit.
    > See http://www.semanticdesigns.com/Products/DMS/DMSToolkit.html.


    Thanks. I already wrote a SAX compiler myself, but I have not gotten
    around to releasing it yet. I think all those methods are overkills in
    this case, because the mapping from SAX callback to generated code are
    straightforward.

    --
    Henri Sivonen

    http://iki.fi/hsivonen/
     
    Henri Sivonen, Jan 16, 2005
    #3
  4. Henri Sivonen, Jan 19, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kirill Simonov
    Replies:
    0
    Views:
    352
    Kirill Simonov
    May 8, 2006
  2. Kirill Simonov
    Replies:
    1
    Views:
    333
    Scott David Daniels
    May 15, 2006
  3. Kirill Simonov
    Replies:
    0
    Views:
    257
    Kirill Simonov
    Jun 19, 2006
  4. Kirill Simonov
    Replies:
    0
    Views:
    294
    Kirill Simonov
    Aug 20, 2006
  5. Erik Wasser
    Replies:
    5
    Views:
    468
    Peter J. Holzer
    Mar 5, 2006
Loading...

Share This Page