XML Parsing into MySQL


I had to write a utility for the Mavericks project to allow me to import asset descriptions that were exported from ContentDM via a tweaked XML format, into a MySQL database for use in Pachyderm authoring. I was going to write a simple python or php script to do it, but realized just how much simpler it would be in WebObjects. Using JDOM to parse the xml into a DOM Document, and then passing the data into an EOEnterpriseObject to be persisted into the database. Access to both libraries made my code insanely simple.

It's possible that it would be as simple in another environment, but I doubt I could have done it any faster or simpler in anything else. WebObjects really does rock.

My code is essentially one line to trigger parsing of the XML to the Document, 2 lines to create the EO and insert it into an editing context, a bunch of lines to populate the attributes of the EO with the various values in the XML ( nothing more complicated than record.setTitle(xmlElement.getChildText("Title"));), and a line to save the pending changes in the editing context. Easy peasy.


See Also

comments powered by Disqus