Tuesday, May 22, 2007

We need an E4X like XML parser for Java


So we could replace the ugly code blocks like


/*Get the value of attribute "id" of the first "account" element in the document */
NodeList nodes = doc.getElementsByTagName("account")
Element account = (Element)nodes.item(0);
String id = account.getAttribute("id");

with something like

String id = doc.account[0].id;

Wouldn't that be cool?! Better than DOM, SAX, StaX or even XPath to some extent from a usability perspective. But it looks like this ease of use is reserved exclusively for the javascript developers for now :( .. Btw it looks like you can already do this in Ruby using REXML as explained in this excellent article.

Hope rest of the programming world would catch up soon...

No comments: