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?

2

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

Comments

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/

1 Comment

This is C#, not Java.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.