[jdom-interest] building a large xml file

Matthew MacKenzie matt at xmlglobal.com
Thu Feb 22 08:04:34 PST 2001


Two Options:

1. Use StringBuffers and build the xml yourself as you process the lines,
2. Build a org.jdom.Element for each line and output it when processing
that line is
   complete using org.jdom.outputter.XMLOutputter.

I advocate (2) because you are less likely to generate bad XML. Here is
code which is probably not correct which show an example:

private static final String DELIMITER = ",";
private static final String FILE_NAME = "data.txt";

HashMap fMap = new HashMap();
fMap.put(new Integer(0), "TagNameForField0");
fMap.put(new Integer(1), "TagNameForFiels1");
// ... to 100 or whatever.

BufferedReader dRead = new BufferedReader(new FileReader(FILE_NAME));
String ln;
XMLOutputter outputter = new XMLOutputter("\t", true);

System.out.println("<?xml version=\"1.0\"?>\n<RootElement>");

while ((ln = dRead.readLine()) != null) {
	StringTokenizer toker = new StringTokenizer(ln, DELIMITER);
	int fieldNum = 0;
	Element thisEl = new Element("Row");
	while (toker.hasMoreElements()) {
		Element kid = new Element(fMap.get(new Integer(fieldNum)));
		outputter.output(thisEl, System.out);


Matthew MacKenzie
VP Research & Development
XML Global Technologies, Inc.

-----Original Message-----
From: jdom-interest-admin at jdom.org
[mailto:jdom-interest-admin at jdom.org]On Behalf Of Mirko Wolf - CBS
Sent: February 22, 2001 7:07 AM
To: jdom-interest at jdom.org
Subject: [jdom-interest] building a large xml file

i've a flat file containing aprox 30000 lines with 100 fields each line.
Every field refers to a  xml-tag. I'm not sure, if my application can
the hole data at once, so i would read a single line from the file,
it and write it as part to my output xml-file. Is this possible? Are the
other solutions to handle such large data?

Regards    Mirko

To control your jdom-interest membership:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 2879 bytes
Desc: not available
Url : http://jdom.org/pipermail/jdom-interest/attachments/20010222/617b5169/smime.bin

More information about the jdom-interest mailing list