Java XML vs .NET Framework

The Java framework feels like a low level .NET framework.

.NET has a lot of convenience functions that make doing common things easy, and the more I work with Java, the more I yearn for that.

Today’s example: I want to load some XML and extract some text from a node.

.NET code:


1
2
3
4
XmlDocument doc = new XmlDocument();
doc.Load("myFile.xml");
XmlNode node = doc.SelectNode("/item/description");
string description = node.InnerText;

The equivalent Java code:


1
2
3
4
5
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = builder.parse("myFile.xml);
XPath xpath = XPathFactory.newInstance().newXPath();
Node node = (Node)xpath.evaluate("/item/description", doc, XPathConstants.NODE);
String description = node.getTextContent();

Which of these two APIs would you rather work with?