org.graphdrawing.graphml.writer
Interface XmlWriter

All Known Implementing Classes:
DomXmlWriter

public interface XmlWriter

Abstraction of XML output classes that provide a consistent way to write Xml elements to some output


Method Summary
 void addNamespace(String URI, String prefix)
          Add a namespace declaration to the root element of the output.
 void setDTD(String sysId)
          Add a DTD system ID to the root element.
 void setDTD(String sysId, String publicId)
          Add a DTD system ID and a DTD public ID to the root element.
 void setEncoding(String encoding)
          Set the document's encoding Calling this method after writeStartDocument(String, String, String) has undefined results.
 void setWriteXmlDeclaration(boolean writeDecl)
          Set if the XML declaration at the beginning of the document should be written.
 XmlWriter writeAttribute(String localName, boolean value)
          Overload of writeAttribute(String, String) for integer values
 XmlWriter writeAttribute(String localName, double value)
          Overload of writeAttribute(String, String) for double values
 XmlWriter writeAttribute(String localName, long value)
          Overload of writeAttribute(String, String) for integer values
 XmlWriter writeAttribute(String localName, String value)
          Write a Xml attribute node.
 XmlWriter writeAttribute(String prefix, String localName, String ns, String value)
          Write a Xml attribute node.
 XmlWriter writeCDATA(String s)
          Write a CDATA section.
 XmlWriter writeComment(String comment)
          Write a Xml comment node
 XmlWriter writeDocumentFragment(DocumentFragment frag)
          Write a document fragment.
 XmlWriter writeEndDocument()
          Close the output.
 XmlWriter writeEndElement()
          Close a XML element previously opened with writeStartElement(String,String) or writeStartElement(String,String,String).
 XmlWriter writeProcessingInstruction(String target, String pi)
          Write a processing instruction
 XmlWriter writeRaw(String s)
          Write a raw content to the result.
 XmlWriter writeStartDocument(String prefix, String docTag, String nsURI)
          Begin the output process
 XmlWriter writeStartElement(String localName, String ns)
          Begin a new XmlElement with given parameters.
 XmlWriter writeStartElement(String prefix, String localName, String ns)
          Begin a new Xml element with given parameters.
 XmlWriter writeText(String s)
          Write a text node.
 

Method Detail

writeComment

public XmlWriter writeComment(String comment)
Write a Xml comment node

Parameters:
comment - The content of the comment
Returns:
the writer instance, to allow for output chaining

writeProcessingInstruction

public XmlWriter writeProcessingInstruction(String target,
                                            String pi)
Write a processing instruction

Parameters:
target - the target of the processing instruction
pi - the instruction itself
Returns:
the writer instance, to allow for output chaining

writeStartDocument

public XmlWriter writeStartDocument(String prefix,
                                    String docTag,
                                    String nsURI)
                             throws GraphMLWriteException
Begin the output process

Returns:
the writer instance, to allow for output chaining
Throws:
GraphMLWriteException

writeEndDocument

public XmlWriter writeEndDocument()
                           throws GraphMLWriteException
Close the output.

Attemps to write to the same document after this method has been called will have undefined results.

Returns:
the writer instance, to allow for output chaining
Throws:
GraphMLWriteException

writeStartElement

public XmlWriter writeStartElement(String prefix,
                                   String localName,
                                   String ns)
Begin a new Xml element with given parameters.

All subsequent output is attched to this element until writeEndElement() has been called or a new element has been started.

Parameters:
prefix - The namespace prefix to use for this element
localName - The local name of this element
ns - The namespace URI of this element
Returns:
the writer instance, to allow for output chaining

writeStartElement

public XmlWriter writeStartElement(String localName,
                                   String ns)
Begin a new XmlElement with given parameters.

All subsequent output is attched to this element until writeEndElement() has been called or a new element has been started.
This acts like writeStartElement(String,String,String), but uses the default prefix for the namespace.

Parameters:
localName - The local name of this element.
ns - The namespace URI of this element
Returns:
the writer instance, to allow for output chaining

writeEndElement

public XmlWriter writeEndElement()
Close a XML element previously opened with writeStartElement(String,String) or writeStartElement(String,String,String).

Returns:
the writer instance, to allow for output chaining

writeAttribute

public XmlWriter writeAttribute(String prefix,
                                String localName,
                                String ns,
                                String value)
Write a Xml attribute node.

The attribute is attached to the closest open Xml element that has been started with writeStartElement(String,String) or writeStartElement(String,String,String)

Parameters:
prefix - The namespace prefix of the attribute
localName - The local name of the attribute
ns - The namespace URI of this attribute
value - The value of this attribute
Returns:
the writer instance, to allow for output chaining

writeAttribute

public XmlWriter writeAttribute(String localName,
                                String value)
Write a Xml attribute node.

The attribute is attached to the closest open Xml element that has been started with writeStartElement(String,String) or writeStartElement(String,String,String)
This method acts like writeAttribute(String,String,String,String), but does not use namespaces or prefixes.

Parameters:
localName - The local name of the attribute
value - The value of this attribute
Returns:
the writer instance, to allow for output chaining

writeAttribute

public XmlWriter writeAttribute(String localName,
                                double value)
Overload of writeAttribute(String, String) for double values

Parameters:
localName - the local name of the attribute
value -
Returns:
the writer instance, to allow for output chaining

writeAttribute

public XmlWriter writeAttribute(String localName,
                                long value)
Overload of writeAttribute(String, String) for integer values

Parameters:
localName - the local name of the attribute
value -
Returns:
the writer instance, to allow for output chaining

writeAttribute

public XmlWriter writeAttribute(String localName,
                                boolean value)
Overload of writeAttribute(String, String) for integer values

Parameters:
localName - the local name of the attribute
value -
Returns:
the writer instance, to allow for output chaining

writeText

public XmlWriter writeText(String s)
Write a text node.

Parameters:
s - The content of the text node
Returns:
the writer instance, to allow for output chaining

writeRaw

public XmlWriter writeRaw(String s)
                   throws GraphMLWriteException
Write a raw content to the result. No output escaping will occur, however, an implementation is free to change the actual value written to the document as long as it is semantically equivalent. The content must be wellformed XML content

Parameters:
s - raw XML content
Returns:
the writer instance, to allow for output chaining
Throws:
GraphMLWriteException - if s does not represent wellformed XML content.

writeDocumentFragment

public XmlWriter writeDocumentFragment(DocumentFragment frag)
Write a document fragment.

Parameters:
frag - the document fragment
Returns:
the writer instance, to allow for output chaining

writeCDATA

public XmlWriter writeCDATA(String s)
Write a CDATA section. Note: it is not possible to nest CDATA sections

Parameters:
s - The content of the text node
Returns:
the writer instance, to allow for output chaining

addNamespace

public void addNamespace(String URI,
                         String prefix)
Add a namespace declaration to the root element of the output. Calling this method after writeStartDocument(String, String, String) has undefined results

Parameters:
URI - the namespace URI of the declaration
prefix - the namespace prefix of the declaration

setDTD

public void setDTD(String sysId)
Add a DTD system ID to the root element. If this is set to null, no DTD reference will be inserted, otherwise, a declaration will be inserted Calling this method after writeStartDocument(String, String, String) has undefined results.

Parameters:
sysId - the SYSTEM ID of the DTD

setEncoding

public void setEncoding(String encoding)
Set the document's encoding Calling this method after writeStartDocument(String, String, String) has undefined results.

Parameters:
encoding - A valid encoding scpecification

setWriteXmlDeclaration

public void setWriteXmlDeclaration(boolean writeDecl)
Set if the XML declaration at the beginning of the document should be written.

Parameters:
writeDecl -

setDTD

public void setDTD(String sysId,
                   String publicId)
Add a DTD system ID and a DTD public ID to the root element. If sysId is set to null, no DTD reference will be inserted. If sysId != null and publicId == null, only a system declaration will be inserted. Otherwise, both declarations will be inserted. Calling this method after writeStartDocument(String, String, String) has undefined results.

Parameters:
sysId - the SYSTEM ID of the DTD
publicId - the PUBLIC ID of the DTD


Copyright ©2000-2009, yWorks GmbH. All rights reserved.