1
/* Copyright 2002, 2003 Elliotte Rusty Harold
3
This library is free software; you can redistribute it and/or modify
4
it under the terms of version 2.1 of the GNU Lesser General Public
5
License as published by the Free Software Foundation.
7
This library is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU Lesser General Public License for more details.
12
You should have received a copy of the GNU Lesser General Public
13
License along with this library; if not, write to the
14
Free Software Foundation, Inc., 59 Temple Place, Suite 330,
15
Boston, MA 02111-1307 USA
17
You can contact Elliotte Rusty Harold by sending e-mail to
18
elharo@metalab.unc.edu. Please include the word "XOM" in the
19
subject line. The XOM home page is located at http://www.xom.nu/
22
package nu.xom.samples;
24
import java.io.FileInputStream;
25
import java.io.FileOutputStream;
26
import java.io.IOException;
27
import java.io.InputStream;
28
import java.io.OutputStream;
29
import java.util.Iterator;
30
import java.util.List;
33
import nu.xom.Document;
34
import nu.xom.Serializer;
40
* Demonstrates building a structured XML document,
41
* from flat, tabular data. A different version of this
42
* example was originally developed for Chapter 4 of
43
* <cite><a target="_top"
44
* href="http://www.cafeconleche.org/books/xmljava/">Processing
45
* XML with Java</a></cite>.
48
* @author Elliotte Rusty Harold
52
public class HierarchicalXMLBudget {
54
public static void convert(List budgetData, String year,
55
OutputStream out) throws IOException {
57
Budget budget = new Budget(year);
58
Iterator records = budgetData.iterator();
59
while (records.hasNext()) {
60
Map lineItem = (Map) records.next();
64
Document doc = new Document(budget.getXML());
65
Serializer sout = new Serializer(out, "UTF-8");
71
public static void main(String[] args) {
75
if (args.length < 2) {
77
"Usage: nu.xom.samples.HierarchicalXMLBudget year infile outfile");
81
// simple error checking on the year value
83
if (!args[0].equals("TransitionalQuarter")) {
84
Integer.parseInt(args[0]);
87
catch (NumberFormatException ex) {
89
"Usage: HierarchicalXMLBudget year infile outfile");
93
InputStream in = new FileInputStream(args[1]);
95
if (args.length < 3) {
99
out = new FileOutputStream(args[2]);
102
List results = BudgetData.parse(in);
103
convert(results, args[0], out);
105
catch (IOException e) {
106
System.err.println(e);
b'\\ No newline at end of file'