473,386 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

XML to Java SAX emitter compiler

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
hs******@iki.fi
http://iki.fi/hsivonen/
Jul 20 '05 #1
3 1883
"Henri Sivonen" <hs******@iki.fi> wrote in message
news:hs****************************@news.dnaintern et.net...
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/Produ...MSToolkit.html.
--
Ira D. Baxter, Ph.D., CTO 512-250-1018
Semantic Designs, Inc. www.semdesigns.com
Jul 20 '05 #2
In article <cs********@enews4.newsguy.com>,
"Ira Baxter" <id******@semdesigns.com> wrote:
"Henri Sivonen" <hs******@iki.fi> wrote in message
news:hs****************************@news.dnaintern et.net...
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/Produ...MSToolkit.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
hs******@iki.fi
http://iki.fi/hsivonen/
Jul 20 '05 #3
In article <hs****************************@news.dnainternet.n et>,
Henri Sivonen <hs******@iki.fi> wrote:
Thanks. I already wrote a SAX compiler myself, but I have not gotten
around to releasing it yet.


Now released: http://hsivonen.iki.fi/saxcompiler/

--
Henri Sivonen
hs******@iki.fi
http://iki.fi/hsivonen/
Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: ptaz | last post by:
Hi I'm trying to run a web page but I get the following error. Ca anyone please tell me a solution to this. Thanks Ptaz HTTP Status 500 - type Exception report
133
by: Gaurav | last post by:
http://www.sys-con.com/story/print.cfm?storyid=45250 Any comments? Thanks Gaurav
289
by: napi | last post by:
I think you would agree with me that a C compiler that directly produces Java Byte Code to be run on any JVM is something that is missing to software programmers so far. With such a tool one could...
1
by: Markus Wollny | last post by:
Hi! I am trying to build PostgreSQL 7.4.3 with Java enabled; I've got Apache Ant version 1.5 and j2sdk1.4.1_05 installed: Verifiying ant: # which javac /usr/java/j2sdk1.4.1_05/bin/javac #...
8
by: Gabriele | last post by:
I'm studying differences between those two architecture in order to choose a setup to develop a completely new application. I'm a programmer with some experience on C++ and PHP and i have basic...
5
by: r035198x | last post by:
Setting up. Getting started To get started with java, one must download and install a version of Sun's JDK (Java Development Kit). The newest release at the time of writting this article is...
0
by: r035198x | last post by:
Inheritance We have already covered one important concept of object-oriented programming, namely encapsulation, in the previous article. These articles are not articles on object oriented...
1
by: hostel | last post by:
HTML PAGE <html> <body> <form action="second.jsp" method="get"> YOur name <input type=text name="name"> <input type=submit > </form> </body> </html>
0
by: Kirill Simonov | last post by:
======================== Announcing PyYAML-3.06 ======================== A new bug fix release of PyYAML is now available: http://pyyaml.org/wiki/PyYAML Changes
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.