This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have David & Dawn Griffiths on-line!
See this thread for details.
Win a copy of Head First Android this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

xml creation

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you use jsse.jar and sax2.jar in your java classpath
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic