• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

xml creation

Shyam Sunder
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Freinds this is my java to xml source code and iam using dom4j.jar

import java.io.FileWriter;

import java.io.IOException;

import org.dom4j.Document;

import org.dom4j.DocumentHelper;

import org.dom4j.Element;

import org.dom4j.io.XMLWriter;

public class XMLFileCreator {
public XMLFileCreator(String strFilePath) {

boolean bFileCreation = false;

bFileCreation = createFile(strFilePath);


public Document createXMLDocument() {

Document document = null;

Element root = null;

Element childElem = null;
document = DocumentHelper.createDocument();

root = document.addElement("DBVALUE");
for (int p = 0; p < 5; p++) {

childElem = root.addElement("ADDRESS", "" + p).addAttribute("NAME", "Name").addAttribute("FNAME", "Name-F" + p).addAttribute("LNAME", "Name-L" + p);

childElem = root.addElement("ADDRESS", "" + p).addAttribute("VALUE", "Value-" + p);


return document;


public boolean createFile(String strFilePath) {

boolean bFileCreated = false;

Document document = null;

try {

XMLWriter writer = new XMLWriter(new FileWriter(strFilePath));

document = createXMLDocument();


bFileCreated = true;

} catch (IOException e) {



return bFileCreated;


public static void main(String[] args) {

new XMLFileCreator("D:/EclipseProjects/files/my.xml");



by using this code i want to create below xml file.
but in the above program values are hard coded. But in my case values may change (except headings). For heading i have to use properties file(struts).
but i don't know how to use properties file
and how to iterate values by using arraylist or any hashmap. just modify the above file and so that i can use the code.

<?xml version="1.0" encoding="utf-8" ?>
- <cdrack to="26-MAY-2004">
<fdate from="21-MAY-2004" to="26-MAY-2004" />
- <information>
<headings col1="BRANCH" col2="BASENO" col3="CUSTOMER NAME" col4="VOLUME ACCOUNT NO" col5="OPENING DATE" />
<field BRANCH="600" BASE_NO="8010070459" CUSTOMER_NAME="B BANIF SA" ACCOUNT_NO="70325368" OPENING_DATE="2003-07-26" />
<field BRANCH="600" BASE_NO="8010070459" CUSTOMER_NAME="BAN BN BANIF SA" ACCOUNT_NO="70325376" OPENING_DATE="2003-07-26" />
<field BRANCH="900" BASE_NO="8010070459" CUSTOMER_NAME="SUNDER" ACCOUNT_NO="9989" OPENING_DATE="2006-07-22" />

Thanks & Regards
Neerav Narielwala
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you use jsse.jar and sax2.jar in your java classpath
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic