<dependencies> <dependency> <groupId>org.xmlwriter</groupId> <artifactId>xmlwriter</artifactId> <version>2.2</version> </dependency> </dependencies> import java.io.FileWriter; import java.io.IOException; import org.xmlwriter.*; public class XMLWriterExample { public static void main(String[] args) { try { XMLWriter writer = new XMLWriter(new FileWriter("output.xml")); writer.startDocument(); writer.startElement("bookstore"); writer.startElement("book"); writer.addAttribute("genre", "fantasy"); writer.addAttribute("publication", "2001"); writer.writeText("Harry Potter and the Philosopher's Stone"); writer.endElement(); writer.endElement(); writer.endDocument(); writer.close(); } catch (IOException e) { e.printStackTrace(); } } } <bookstore> <book genre="fantasy" publication="2001">Harry Potter and the Philosopher's Stone</book> </bookstore> properties xmlwriter.indent=true xmlwriter.lineSeparator= xmlwriter.indentAmount=2


上一篇:
下一篇:
切换中文