Question: How to create a xml file and save it in some place in my machine using java..there are attributes also include in the xml file? I have found org.w3c.dom.Document but having problems with creating attributes for elements and save the xml file.

Thank You.

Answer: 
You can use [Xembly](https://github.com/yegor256/xembly), a small open source library that makes this XML creating process much more intuitive:

```
String xml = new Xembler(
  new Directives()
    .add("root")
    .add("order")
    .attr("id", "553")
    .set("$140.00")
).xml();

```

Xembly is a wrapper around native Java DOM, and is a very lightweight library.
Have look at [**dom4j**](http://sourceforge.net/projects/dom4j/) or [**jdom**](http://www.jdom.org/). Both libraries allow creating a Document and allow printing the document as xml. Both are widly used, pretty easy to use and you'll find a lot of examples and snippets.

[dom4j - Quick start guide](http://dom4j.sourceforge.net/dom4j-1.6.1/guide.html)