How can I write multiple XML files using one sketch
Does anybody have some advice on how I can write multiple XML files with only the code of one sketch. I'm trying to do this using the ProXML library but that doesn't work. For some reason,开发者_StackOverflow中文版 one of the two XML files is 'polluted' with data that should only be in the other file.
Thanks
A simpler approach is to use the printwriter, and writing XMLElement.toString() for the content of your files:
XMLElement xmle1 = ...;
PrintWriter output = createWriter("file_1.xml");
output.println(xmle1.toString());
output.flush(); // always flush before closing, just to be sure
output.close();
XMLElement xmle2 = ...;
output = createWriter("file_2.xml");
output.println(xmle2.toString());
output.flush();
output.close();
This does not generate xml files with a doctype, but they're certainly Processing-compatible in that the written XML can be read back in to form an equivalent XMLElement.
(reference page for PrintWriter: http://processing.org/reference/PrintWriter.html)
精彩评论