0

Given a pre-described set of tags which I can use(for example, a structure like the AndroidManifest.xml), how can I create an XML document (for a manifest file) from scratch in Java, preferably not using any third party libraries?

Also, what is(if any) the best way to do this?

Pawan
  • 1,480
  • 2
  • 18
  • 27
  • Possible duplicate of : http://stackoverflow.com/questions/7373567/java-how-to-read-and-write-xml-files – Abdul Fatir May 27 '14 at 12:30
  • There are several ways to read and write XML files. SAX, DOM, JAXB (all included in the JRE) and [many more](https://stackoverflow.com/questions/4898590/generating-xml-using-sax-and-java) (there are some examples, especially using the [XML Stream Writer](http://stackoverflow.com/a/4898623/1692341)). – Steffen May 27 '14 at 12:31

2 Answers2

3

There are many ways to generate XML without third party framework

  1. SAX and DOM (powerful yet complex)
  2. Jax-B (relatively easy)

The simplest way to generate an XML is to use Jax-B (which comes as a standard from JEE6 onwards).Refer here for more details on Jax-B

But if your trying to implement this in Android(since you mentioned AndroidManifest.xml) then I recommend you to use some third party framework like Simple to avoid unwanted complications, because it is more lightweight than the rest of the above mentioned technologies and easy to use.

If your strict on not using third party library(which I do not recommend), then use SaxParser in Android, refer here for some examples.

Hope this helps

Adheep
  • 1,585
  • 1
  • 14
  • 27
1
Overview of Java DOM API for XMLType

Oracle XML DB supports the Java Document Object Model (DOM) Application Program Interface (API) for XMLType. This is a generic API for client and server, for both XML schema-based and non-schema-based documents. It is implemented using the Java package oracle.xdb.dom. DOM is an in-memory tree-based object representation of XML documents that enables programmatic access to their elements and attributes. The DOM object and interface are part of a W3C recommendation. DOM views the parsed document as a tree of objects.

http://docs.oracle.com/cd/B19306_01/appdev.102/b14259/xdb11jav.htm

http://www.c-sharpcorner.com/UploadFile/yougerthen/how-to-generate-an-xml-document-programmatically-using-system-xml-xmlwriter-part-iii/

Macrosoft-Dev
  • 2,195
  • 1
  • 12
  • 15