aspose file tools*
The moose likes XML and Related Technologies and the fly likes xml creation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "xml creation" Watch "xml creation" New topic
Author

xml creation

Shyam Sunder
Greenhorn

Joined: Dec 23, 2006
Posts: 24
hi,
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();
writer.write(document);

writer.close();

bFileCreated = true;

} catch (IOException e) {

e.printStackTrace();

}



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" />
</information>
</cdrack>

Thanks & Regards
Shyam
Neerav Narielwala
Ranch Hand

Joined: Dec 08, 2006
Posts: 106
I think you use jsse.jar and sax2.jar in your java classpath


<a href="http://www.java-tips.org/java-tutorials/tutorials/" target="_blank" rel="nofollow">Java Tutorials</a> | <a href="http://www.planet-java.org" target="_blank" rel="nofollow">Java Weblog</a> | <a href="http://computer-engineering.science-tips.org" target="_blank" rel="nofollow">Computing Articles</a>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: xml creation
 
Similar Threads
Dom4j new lines
Can anyone help?I still can't append records in xml...
How to Retrieve DOM
jdom xml schema validation
method to create header