List bugInstanceList = document.selectNodes("/BugCollection/BugInstance");  out.write("@relation "); out.write(relationName); out.write("\n\n");  for (Iterator i = bugInstanceList.iterator(); i.hasNext(); ) { final Element element = (Element) i.next(); scanAttributeList(new AttributeCallback() { public void apply(Attribute attribute) throws MissingNodeException { attribute.scan(element); } }); }  scanAttributeList(new AttributeCallback() { public void apply(Attribute attribute) throws IOException { out.write("@attribute "); out.write(attribute.getName()); out.write(" "); out.write(attribute.getRange()); out.write("\n"); } }); out.write("\n");  out.write("@data\n");  for (Iterator i = bugInstanceList.iterator(); i.hasNext(); ) { final Element element = (Element) i.next(); scanAttributeList(new AttributeCallback() { boolean first = true; public void apply(Attribute attribute) throws IOException { if (!first) out.write(","); first = false; String value; try { value = attribute.getInstanceValue(element); } catch (MissingNodeException e) { value = "?"; } out.write(value); } }); out.write("\n"); }
scan(document); generateHeader(relationName, out); generateInstances(document, out);
	public void convert(String relationName, Document document, final Writer out)			throws IOException, MissingNodeException {		List bugInstanceList = document.selectNodes("/BugCollection/BugInstance");		out.write("@relation ");		out.write(relationName);		out.write("\n\n");		for (Iterator i = bugInstanceList.iterator(); i.hasNext(); ) {			final Element element = (Element) i.next();			scanAttributeList(new AttributeCallback() {				public void apply(Attribute attribute) throws MissingNodeException {					attribute.scan(element);				}			});		}		scanAttributeList(new AttributeCallback() {			public void apply(Attribute attribute) throws IOException {				out.write("@attribute ");				out.write(attribute.getName());				out.write(" ");				out.write(attribute.getRange());				out.write("\n");			}		});		out.write("\n");		out.write("@data\n");		for (Iterator i = bugInstanceList.iterator(); i.hasNext(); ) {			final Element element = (Element) i.next();			scanAttributeList(new AttributeCallback() {				boolean first = true;				public void apply(Attribute attribute) throws IOException {					if (!first)						out.write(",");					first = false;					String value;					try {						value = attribute.getInstanceValue(element);					} catch (MissingNodeException e) {						value = "?";					}					out.write(value);				}			});			out.write("\n");		}	}