What is the basic difference between Element and Node in Java. I just cam across this while manipulating XML node.
Also is there any way where I can set value for particular node/element? ie <Name></Name> should be changed to <Name>Bob</Name> I am not able to do it. But I can very well set attribute within the node, for example <Name value="Bob"/>
I guess you are talking about interface Node and interface Element in package org.w3c.dom. Have you looked at the API documentation for those interfaces?
Element is a subinterface of Node. An Element represents an element in an XML document, so something that begins with a start tag and ends with an end tag. An Element is a Node, but there are other things besides Element which are also Nodes. For example, attributes, comments etc. are also Nodes, but not Elements.
The org.w3c.dom API is not very well suited for editing XML documents - it is meant mainly for reading XML documents. If you want to edit XML documents, an API like JDOM is much easier to use.
Please do not recommend jdom to new user any more. Jdom has stopped development on 2004. It is getting obsolete now. Don't get me wrong, I am using jdom since the very early edition, and directly got the idea from one of jdom authors in person.
However, things have changed now. Please use xerces, dom4j, xpp, etc. instead.
If you are going to use the DOM in the standard Java library you should get really familiar with the table in the Javadocs for the Node interface in the org.w3c.dom package. There are 12 different subinterfaces of Node - each with its own peculiarities summarized in that table.
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop