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

For reading XML, there are SAX and DOM built into Java 1.5. You can use JAXP and not know the details of what a parser is. So, what are the prescribed APIs for XML documents written in Java 1.5 and earlier?

  • I do not want to use a third-party binary
  • I do not want to accept Sun VM or IBM VM, etc. and use some specialized class
  • Regardless of what is in the document, I would like to read an additional way.
  • Performance and suitability for large XML files is not particularly important.

Ideally, reading and writing unchanged is just a few lines of code.

+5
source share
2

Java 1.4 javax.xml.transform, DOMSource, SAXSource ..:

// 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);

API J2SE 1.3, (, J2EE API , - - ).

+5

"" API, :

XmlWriter, Writer , startElement( String name ), writeAttribute( String name, String value ) writeCData( String text ).

. , escape- SGML; . Apache Commons , .

, , , . , -, <element/>.

0

All Articles