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?
October 6th, 2005 at 2:11 am
I’m curious, are you learning Java for a new job or for your own satisfaction. I’ve been thinking of getting aquainted myself and would be interested in any good resources you find.
December 19th, 2005 at 10:32 pm
You need to look at XMLBeans.