Reading and writing XML using JUST Java 1.5 (or earlier)

Dilum Ranatunga :

For reading XML, there is SAX and DOM built into Java 1.5. You can use JAXP and not need to know details about what parser is available... So, what are some prescribed APIs for one to write XML documents in Java 1.5 and earlier?

  • I don't want to use a third party binary
  • I don't want to assume a Sun VM or IBM VM etc and use some specialized class
  • Whatever means there is of writing the document, I would like to read in a complementary way.
  • Performance and suitability for large XML files is not particularly important

Ideally, a read-and-write with no changes is just a few lines of code.

McDowell :

Java 1.4 comes with javax.xml.transform, which can take a DOMSource, SAXSource, etc:

// print document
InputSource inputSource = new InputSource(stream);
Source saxSource = new SAXSource(inputSource);
Result result = new StreamResult(System.out);
TransformerFactory transformerFactory = TransformerFactory
    .newInstance();
Transformer transformer = transformerFactory
    .newTransformer();
transformer.transform(saxSource, result);

If you want to go back to the J2SE 1.3 API, you're pretty much on your own (though if you're on the J2EE API of that era, there might be something - I don't recall).

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related