nl.knowledgeplaza.util.io
Class XmlWriter

java.lang.Object
  extended by nl.knowledgeplaza.util.io.XmlWriter
All Implemented Interfaces:
Closeable

public class XmlWriter
extends Object
implements Closeable

XmlWriter derived from / inspired on / extended from / API compatible with http://code.google.com/p/osjava/wiki/XmlWriter Only this implementation has a few problems, like no XMLNS support on nodes and some issues with the ttty printer. This class does not do any validation checking, it just helps writing pretty printed XML Usage: OutputStreamWriter w = new OutputStreamWriter(new FileOutputStream("c:/tmp/test.xml"),"UTF-8"); XmlWriter lXmlWriter = new XmlWriter(w); lXmlWriter.writeXmlVersion("1.0", "UTF-8"); lXmlWriter.writeEntity("root"); lXmlWriter.writeXmlns(null, "urn:iso:std:iso:20022:tech:xsd:pain.001.001.03", ""); lXmlWriter.writeXmlns("xsi", "http://www.w3.org/2001/XMLSchema-instance", "urn:iso:std:iso:20022:tech:xsd:pain.001.001.03 [LOCATION] pain.001.001.03.xsd"); lXmlWriter.writeEntity("node1"); lXmlWriter.writeAttribute("attr1", "value1"); lXmlWriter.writeAttribute("attr2", "value2"); lXmlWriter.writeAttribute("attr3", "value3"); lXmlWriter.writeEntityWithText("txtnode", "some text"); lXmlWriter.endEntity(); lXmlWriter.endEntity(); lXmlWriter.close();

Author:
Tom Eugelink TODO: convenience methods for number and date formatting

Constructor Summary
XmlWriter(Writer writer)
           
 
Method Summary
 void close()
           
 XmlWriter endEntity()
           
 void flush()
          Flushes the stream.
 boolean getPretty()
           
static void main(String[] args)
           
 void setPretty(boolean value)
           
 XmlWriter writeAttribute(String id, String value)
           
 XmlWriter writeEntity(String name)
          write an entity
 XmlWriter writeEntityWithText(String name, String text)
           
 XmlWriter writeText(String text)
           
 XmlWriter writeXmlns(String id, String value, String schemaLocation)
          write XMLNS info
 XmlWriter writeXmlVersion(String version, String encoding)
          write xml version info
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XmlWriter

public XmlWriter(Writer writer)
Parameters:
writer -
Method Detail

setPretty

public void setPretty(boolean value)

getPretty

public boolean getPretty()

flush

public void flush()
           throws IOException
Flushes the stream.

Throws:
IOException - If an I/O error occurs

close

public void close()
           throws IOException
Specified by:
close in interface Closeable
Throws:
IOException

writeXmlVersion

public XmlWriter writeXmlVersion(String version,
                                 String encoding)
                          throws IOException
write xml version info

Parameters:
version -
encoding -
Throws:
IOException

writeEntity

public XmlWriter writeEntity(String name)
                      throws IOException
write an entity

Parameters:
name -
Throws:
IOException

endEntity

public XmlWriter endEntity()
                    throws IOException
Parameters:
name -
Throws:
IOException

writeEntityWithText

public XmlWriter writeEntityWithText(String name,
                                     String text)
                              throws IOException
Parameters:
name -
text -
Throws:
IOException

writeAttribute

public XmlWriter writeAttribute(String id,
                                String value)
                         throws IOException
Parameters:
id -
value -
Throws:
IOException

writeXmlns

public XmlWriter writeXmlns(String id,
                            String value,
                            String schemaLocation)
                     throws IOException
write XMLNS info

Parameters:
id - (may be null)
value -
schemaLocation - (may be null)
Throws:
IOException

writeText

public XmlWriter writeText(String text)
                    throws IOException
Parameters:
text -
Throws:
IOException

main

public static void main(String[] args)


Copyright © 2012 KnowledgePlaza. All Rights Reserved.