Skip to content

Instantly share code, notes, and snippets.

@Crydust
Created November 24, 2015 18:15
Show Gist options
  • Save Crydust/d77956cbfa24f6e7b567 to your computer and use it in GitHub Desktop.
Save Crydust/d77956cbfa24f6e7b567 to your computer and use it in GitHub Desktop.
package xyz;
import java.io.Writer;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamWriter;
public class Main {
public static void main(String[] args) throws Exception {
String fileName = "dummy.xml";
try (Writer out = Files.newBufferedWriter(Paths.get(fileName), StandardCharsets.UTF_8)) {
XMLOutputFactory xof = XMLOutputFactory.newInstance();
XMLStreamWriter xtw = xof.createXMLStreamWriter(out);
xtw.writeStartDocument("UTF-8", "1.0");
xtw.writeDTD("<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">");
xtw.writeStartElement("plist");
xtw.writeAttribute("version", "1.0");
xtw.writeStartElement("dict");
xtw.writeCharacters("\n");
xtw.writeStartElement("key");
xtw.writeCharacters("Label");
xtw.writeEndElement();
xtw.writeStartElement("string");
xtw.writeCharacters("xyz");
xtw.writeEndElement();
xtw.writeCharacters("\n");
// dict
xtw.writeEndElement();
// plist
xtw.writeEndElement();
xtw.writeEndDocument();
xtw.flush();
xtw.close();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment