Brian's Waste of Time

Thu, 22 Jan 2004

Atom via XMLBeans

Got tired of futzing learning XSD etc so started on something potentially useful. First step, get Atom feeds working through xmlbeans. Success!


    public void testCreateFeedType()
    {
        AuthorType author = AuthorType.Factory.newInstance();
        author.setEmail("brian@skife.org");
        author.setName("Brian McCallister");
        author.setUrl("http://kasparov.skife.org/blog/");
        assertTrue(author.validate());

        FeedType feed = FeedType.Factory.newInstance();
        feed.setAuthor(author);
        feed.setCopyright("copyright 2004 BMc");
        feed.setId("http://kasparov.skife.org/blog/test.atom");
        feed.setTitle("Test Feed");
        feed.setVersion("0.3");
        feed.setModified(Calendar.getInstance());
        assertTrue(feed.validate());

        FeedDocument doc = FeedDocument.Factory.newInstance();
        doc.setFeed(feed);
        assertTrue(doc.validate());

        System.err.println(doc);
    }

gives me


<feed version="0.3" xmlns="http://purl.org/atom/ns#">
  <title>Test Feed</title>
  <author>
    <name>Brian McCallister</name>
    <url>http://kasparov.skife.org/blog/</url>
    <email>brianm@apache.org</email>
  </author>
  <id>http://kasparov.skife.org/blog/test.atom</id>
  <copyright>copyright 2004 BMc</copyright>
  <modified>2004-01-21T23:26:19.586-05:00</modified>
</feed>

I'll take small victories =) Next step is persisting these things to xindice, and pulling em back out. Then Cocoon enters the picture and the real fun can begin. Oh fun day!

Along the way I learned that despite having someone who knows some shell scripting, BEA has pretty much standardized on Windows for development, I think:


[mccallister@kite ~/src/xml-xmlbeans/v1/bin]$ ls -l
total 112
drwxr-xr-x  5 mccallis  mccallis  170 21 Jan 22:48 CVS
-rwxr-xr-x  1 mccallis  mccallis  198 15 Sep 13:19 dumpxsb
-rw-r--r--  1 mccallis  mccallis  293 15 Sep 13:09 dumpxsb.cmd
-rw-r--r--  1 mccallis  mccallis  344 15 Sep 13:09 jaxbc.cmd
-rw-r--r--  1 mccallis  mccallis  487 15 Sep 13:09 random.cmd
-rwxr-xr-x  1 mccallis  mccallis  179 21 Jan 22:58 scomp
-rw-r--r--  1 mccallis  mccallis  276 15 Sep 13:09 scomp.cmd
-rw-r--r--  1 mccallis  mccallis  272 15 Sep 13:09 scopy.cmd
-rw-r--r--  1 mccallis  mccallis  276 15 Sep 13:09 sdownload.cmd
-rw-r--r--  1 mccallis  mccallis  327 15 Sep 13:09 sfactor.cmd
-rwxr-xr-x  1 mccallis  mccallis  195 15 Sep 13:19 validate
-rw-r--r--  1 mccallis  mccallis  287 15 Sep 13:09 validate.cmd
-rw-r--r--  1 mccallis  mccallis  230 15 Sep 13:09 xpretty.cmd
-rw-r--r--  1 mccallis  mccallis  245 15 Sep 13:09 xsdtree.cmd
-rw-r--r--  1 mccallis  mccallis  217 15 Sep 13:09 xstc.cmd
[mccallister@kite ~/src/xml-xmlbeans/v1/bin]$  

and the scomp compiler shell script doesn't even actually work without some hacking =)

The most interesting bit is that I originally implemented an Atom object model by hand and added the xdoclet tags to generate the OJB and Torque metadata needed to persist atom elements back to a relational database. This was a lot of code. The atom XSD (unofficial one by Randy Morin) on the other hand compiled to all of the needed Java from about 109 lines of xsd.

5 writebacks [/src/java/xmlbeans] permanent link