Posts Tagged: xml

Search for the XML Superstar

IDUG (the International DB2 Users Group) is sponsoring a worldwide contest initiative called The XML challenge – Search for the xml superstar. This contest aims to recognize developers (students or professionals) that create XML solutions, in one of the following categories: Video, Gadget, Query, PortableApp and XML Contest.

They are offering thousands of dollars in prizes, including Wiis, Zunes, iPods, Conference passes, Notebooks, GPS, etc…

If you live in US, you can submit your Video and Gadget entries until December 16th and 17th, respectively. The XML programming contest has also started and submissions will be accepted till January 31st.

For other countries, keep checking the website for updates on your local contest.

Persisting XML with OpenJPA

I’ve been looking at JPA – Java Persistence Architecture and decided to play a bit with OpenJPA using DB2 as the back-end. My goal: to persist and query XML data in DB2, making use of DB2’s pureXML capabilities to query the XML data using SQL/XML‘s XMLQUERY() function.

However, while OpenJPA has an extensive documentation, the examples are not always complete and there isn’t a lot of information on the web regarding OpenJPA error determination and solving. So, here are some recommendations for some of the problems I have encountered. The class xml.Address is the one to be persisted as XML in the database using JPA and it is stored as the field shipAddress of the Order objects.

 [java] Exception in thread "main" <openjpa-1.0.0-r420667:568756 fatal user error>
Type "class xml.Address" does not have persistence metadata. 

Suggestion: Remove the reference to xml.Address from persistence.xml

[java] Exception in thread "main" <openjpa-1.0.0-r420667:568756 nonfatal user error>
Encountered unmanaged object "xml.Address@9b2a51" in
persistent field "xml.Order.shipAddress" of managed object "xml.Order@12b3349"
during flush.  However, this field does not allow cascade persist. 
You cannot flush unmanaged objects.
  [java] FailedObject: xml.Address@9b2a51

Suggestion: Make sure you have no @Entity or @Embeddable annotations in xml.Address. The main annotation is @XmlRootElement.

 [java] Exception in thread "main" <openjpa-1.0.0-r420667:568756 fatal general error>
"xml" doesnt contain ObjectFactory.class or jaxb.index

Suggestion: add a file jaxb.index into your xml package containing all the classes to be persisted as XML: a file containing Address in our case.

DB2 on Rails update

I’m back to fiddling around with my Ruby on Rails experiments(1)(2). I was able to create a very useful 2-way mapping between Ruby objects and xml data stored in DB2 pureXML. Basically, trying to replicate some of ActiveRecord’s functionality but for XML data. I still find it odd, though, that both ROXML and xml-mapping haven’t had much activity as of late. I’m wondering if there is any new OXM library around that I don’t know of.

Also on the same topic:

  • the main DB2 on Rails website is up and running again, with a revamped design and now using wordpress instead of typo.
  • a new version of the ibm_db driver was also released, containing several bugfixes. Update it through gems (gem update ibm_db) or from here: 

XML and Databases

I just stumbled across an excellent resource regarding XML technology in databases. Ronald Bourret has the most extensive research I’ve seen on the global XML and databases state of the art. It has an extensive list of databases with XML support (native or by means of extenders/adapters) recently updated and several papers on XML and databases

A must read, that I will be consuming over the coming weeks. 

Recent readings

XML Mapping in Ruby

Dear lazy web…

I’ve been playing with Ruby and XML lately, and one of the key features I need to use is XML mapping from XML to Ruby objects and vice versa. However, both ROXML and XML::Mapping do not seem to be very active at the moment. Both forums contain un-replied questions  several months old, and I can’t find any examples that are not a couple of years old.

Is there any XML Mapping library for Ruby that is currently active(*)? XML::Mapping was serving me good enough, until the moment that I needed some of the documented features and found that they are not supported in the current release :-(

 (*) by active I don’t mean it needs to be in exclusively in code development, but at least with some recent activity in forums, documentation, examples, etc..

Ruby and libxml in Windows

If you happen to be using Ruby in Windows and need to use libxml and don’t feel like compiling it from the source code, here is an alternative. Charlie Savage did the work himself and provides the binary that you can use instead of compiling your own.

How to replace text in a file with huge lines

This is my problem: I have a huge xml file (150MB), in which I want to rename some of the node names. Conisder the example:


The creators of this document were not aware of namespaces, so they decided to use different prefixes in the element names in the documents created. My goal is to rename all the tags with prefix removing the "prefix_" part of the name. The solution looked simple, but it isn’t.

To begin with, I tried a sed, using the argument "s/prefix_//g". This didn’t work, because in AIX sed only accepts up to 4096 bytes per line (I read somewhere that this doesn’t happen with some sed versions, but I couldn’t spend the whole day trying versions of sed). Using perl also resulted in Out of memmory errors (I’ve just very basic perl knowledge, so there may be a way of handling such big lines).

So, I had to come up with a set of steps to do this change and maintain the file in it’s original format (all contents in one line). The steps where:

  •  used the tr utility to translate all ">" characters into a new line (a new > is printed before the replaced char) using tr  ‘>’ ‘\012’ < $1  | while read line; do echo "${line}>"  >> $ done.
  • rename the tags by removing the prefix. Either use sed or perl with the replacement pattern "s/prefix_//g".
  • delete all the "\n" (newline chars) from the current file, to get back to the one liner format. Used perl to read from one file and write to other applying "s/\n//g" to the content.

I’m sure that this is not the best solution, and there must be some utility out there that I can use so, if you have any idea, just leave a comment.