Writing XML with Java (Writing XML with Java), notes, page 722171
https://www.purl.org/stefan_ram/pub/writing-xml-with-java (permalink) is the canonical URI of this page.
Stefan Ram

Writing XML with Java

Using the Class »XMLSerializer«

XMLSerializerClient.java

public final class XMLSerializerClient
{ public static void main( final java.lang.String[] commandLineArguments )
throws java.lang.Throwable
{ final java.io.FileOutputStream fileOutputStream =
new java.io.FileOutputStream( "tmp.txt" );

com.sun.org.apache.xml.internal.serialize.OutputFormat outputFormat =
new com.sun.org.apache.xml.internal.serialize.OutputFormat
( "XML", "UTF-8", true );

outputFormat.setIndent( 1 );

outputFormat.setIndenting( true );

// outputFormat.setDoctype( null, "users.dtd" );

com.sun.org.apache.xml.internal.serialize.XMLSerializer serializer =
new com.sun.org.apache.xml.internal.serialize.XMLSerializer
( fileOutputStream, outputFormat);

serializer.startDocument();
{ serializer.startElement( "", "example", "example",
new com.sun.org.apache.xml.internal.serializer.
AttributesImplSerializer() );
{ final char[] data = "test text" . toCharArray();
serializer.characters( data, 0, data.length );
serializer.endElement( "", "example", "example" ); }
serializer.endDocument(); }}}

tmp.txt
<?xml version="1.0" encoding="UTF-8"?>
<example>test text</example>

About this page, Impressum  |   Form for messages to the publisher regarding this page  |   "ram@zedat.fu-berlin.de" (without the quotation marks) is the email-address of Stefan Ram.   |   A link to the start page of Stefan Ram appears at the top of this page behind the text "Stefan Ram".)  |   Copyright 1998-2014 Stefan Ram, Berlin. All rights reserved. This page is a publication by Stefan Ram. relevant keywords describing this page: Stefan Ram Berlin slrprd slrprd stefanramberlin spellched stefanram722171 stefan_ram:722171 Writing XML with Java Stefan Ram, Berlin, and, or, near, uni, online, slrprd, slrprdqxx, slrprddoc, slrprd722171, slrprddef722171, PbclevtugFgrsnaEnz Erklärung, Beschreibung, Info, Information, Hinweis,

Copyright 1998-2014 Stefan Ram, Berlin. All rights reserved. This page is a publication by Stefan Ram.
https://www.purl.org/stefan_ram/pub/writing-xml-with-java