Support Wikipedia Follow My Heart: Read and Write XML in JDK1.4 with org.w3c.Dom


Read and Write XML in JDK1.4 with org.w3c.Dom

well, I admitted that org.w3c.dom (or DOM) is quite difficult to use than the popular dom4j (see here).

But sometimes, it might be problem for us to include new libraries in source code due to library confliction or license issues. For example, a big project is developed by various people independently. If all people use different libraries to parse xml, your product will finally turned out to be very complex to maintain.

So sometimes using the standard package in JDK (like JAXP) is the only choice, though difficult.

Here I demo some examples on how to use it for common purpose.


With above code, it becomes easier for you to manipulate XML files.

Here is something important.
Usually, the output format of XML file by DOM is very ugly, with does not change lines or insert indent automatically. So you need to pay attention to the following lines in the method which print out xml files.



OK, I will also paste an example.

XMLResourceBundle class is convinient. But it is only supported by at least JDK1.5.  Now I implemented a XMLResourceBundle class by JDK1.4 using DOM.


.The Class HintUtility did nothing but invoking System.out.println() to print messages.