C# Class SimpleFramework.Xml.Stream.Formatter

The Formatter object is used to format output as XML indented with a configurable indent level. This is used to write start and end tags, as well as attributes and values to the given writer. The output is written directly to the stream with and indentation for each element appropriate to its position in the document hierarchy. If the indent is set to zero then no indent is performed and all XML will appear on the same line.
Mostra file Open project: ngallagher/simplexml Class Usage Examples

Public Methods

Method Description
Append ( String plain ) : void

This is used to buffer characters to the output stream without any translation. This is used when buffering the start tags so that they can be reset without affecting the resulting document.

Append ( char ch ) : void

This is used to buffer a character to the output stream without any translation. This is used when buffering the start tags so that they can be reset without affecting the resulting document.

Data ( String value ) : void

This method is used to write the specified text as a CDATA block within the XML element. This is typically used when the value is large or if it must be preserved in a format that will not be affected by other XML parsers. For large text values this is also faster than performing a character by character escaping.

Escape ( String value ) : void

This is used to write the specified value to the output with translation to any symbol characters or non text characters. This will translate the symbol characters such as "&", ">", "<", and """. This also writes any non text and non symbol characters as integer values like "{".

Escape ( char ch ) : void

This is used to write the specified value to the output with translation to any symbol characters or non text characters. This will translate the symbol characters such as "&", ">", "<", and """. This also writes any non text and non symbol characters as integer values like "{".

Flush ( ) : void

This is used to flush the writer when the XML if it has been buffered. The flush method is used by the node writer after an end element has been written. Flushing ensures that buffering does not affect the result of the node writer.

Formatter ( TextWriter result, Format format ) : System.IO

Constructor for the Formatter object. This creates an object that can be used to write XML in an indented format to the specified writer. The XML written will be well formed.

IsEmpty ( String value ) : bool

This method is used to determine if a root annotation value is an empty value. Rather than determining if a string is empty be comparing it to an empty string this method allows for the value an empty string represents to be changed in future.

IsText ( char ch ) : bool

This is used to determine if the specified character is a text character. If the character specified is not a text value then this returls true, otherwise this returns false.

Symbol ( char ch ) : char[]

This is used to convert the specified character to an XML text symbol if the specified character can be converted. If the character cannot be converted to a symbol null is returned.

Unicode ( char ch ) : String

This is used to convert the the specified character to unicode. This will simply get the decimal representation of the given character as a string so it can be written as an escape.

Write ( String plain ) : void

This is used to write plain text to the output stream without any translation. This is used when writing the start tags and end tags, this is also used to write attribute names.

Write ( String plain, String prefix ) : void

This is used to write plain text to the output stream without any translation. This is used when writing the start tags and end tags, this is also used to write attribute names.

Write ( char ch ) : void

This is used to write a character to the output stream without any translation. This is used when writing the start tags and end tags, this is also used to write attribute names.

WriteAttribute ( String name, String value, String prefix ) : void

This is used to write a name value attribute pair. If the last tag written was not a start tag then this throws an exception. All attribute values written are enclosed in double quotes.

WriteComment ( String comment ) : void

This is used to write any comments that have been set. The comment will typically be written at the start of an element to describe the purpose of the element or include debug data that can be used to determine any issues in serialization.

WriteEnd ( String name, String prefix ) : void

This is used to write an end element tag to the writer. This will close the element with a short /> if the last tag written was a start tag. However if an end tag or some text was written then a full end tag is written.

WriteNamespace ( String reference, String prefix ) : void

This is used to write the namespace to the element. This will write the special attribute using the prefix and reference specified. This will escape the reference if it is required.

WriteProlog ( ) : void

This is used to write a prolog to the specified output. This is only written if the specified Format object has been given a non null prolog. If no prolog is specified then no prolog is written to the generated XML.

WriteStart ( String name, String prefix ) : void

This method is used to write a start tag for an element. If a start tag was written before this then it is closed. Before the start tag is written an indent is generated and placed in front of the tag, this is done for all but the first start tag.

WriteText ( String text ) : void

This is used to write the specified text value to the writer. If the last tag written was a start tag then it is closed. By default this will escape any illegal XML characters.

WriteText ( String text, Mode mode ) : void

This is used to write the specified text value to the writer. If the last tag written was a start tag then it is closed. This will use the output mode specified.

Method Details

Append() public method

This is used to buffer characters to the output stream without any translation. This is used when buffering the start tags so that they can be reset without affecting the resulting document.
public Append ( String plain ) : void
plain String /// This is the string that is to be buffered. ///
return void

Append() public method

This is used to buffer a character to the output stream without any translation. This is used when buffering the start tags so that they can be reset without affecting the resulting document.
public Append ( char ch ) : void
ch char /// This is the character to be written to the output. ///
return void

Data() public method

This method is used to write the specified text as a CDATA block within the XML element. This is typically used when the value is large or if it must be preserved in a format that will not be affected by other XML parsers. For large text values this is also faster than performing a character by character escaping.
public Data ( String value ) : void
value String /// This is the text value to be written as CDATA. ///
return void

Escape() public method

This is used to write the specified value to the output with translation to any symbol characters or non text characters. This will translate the symbol characters such as "&", ">", "<", and """. This also writes any non text and non symbol characters as integer values like "{".
public Escape ( String value ) : void
value String /// The text value to be escaped and written. ///
return void

Escape() public method

This is used to write the specified value to the output with translation to any symbol characters or non text characters. This will translate the symbol characters such as "&", ">", "<", and """. This also writes any non text and non symbol characters as integer values like "{".
public Escape ( char ch ) : void
ch char /// The text character to be escaped and written. ///
return void

Flush() public method

This is used to flush the writer when the XML if it has been buffered. The flush method is used by the node writer after an end element has been written. Flushing ensures that buffering does not affect the result of the node writer.
public Flush ( ) : void
return void

Formatter() public method

Constructor for the Formatter object. This creates an object that can be used to write XML in an indented format to the specified writer. The XML written will be well formed.
public Formatter ( TextWriter result, Format format ) : System.IO
result System.IO.TextWriter /// This is where the XML should be written to. ///
format Format /// This is the format object to use. ///
return System.IO

IsEmpty() public method

This method is used to determine if a root annotation value is an empty value. Rather than determining if a string is empty be comparing it to an empty string this method allows for the value an empty string represents to be changed in future.
public IsEmpty ( String value ) : bool
value String /// This is the value to determine if it is empty. ///
return bool

IsText() public method

This is used to determine if the specified character is a text character. If the character specified is not a text value then this returls true, otherwise this returns false.
public IsText ( char ch ) : bool
ch char /// This is the character to be evaluated as text. ///
return bool

Symbol() public method

This is used to convert the specified character to an XML text symbol if the specified character can be converted. If the character cannot be converted to a symbol null is returned.
public Symbol ( char ch ) : char[]
ch char /// This is the character that is to be converted. ///
return char[]

Unicode() public method

This is used to convert the the specified character to unicode. This will simply get the decimal representation of the given character as a string so it can be written as an escape.
public Unicode ( char ch ) : String
ch char /// This is the character that is to be converted. ///
return String

Write() public method

This is used to write plain text to the output stream without any translation. This is used when writing the start tags and end tags, this is also used to write attribute names.
public Write ( String plain ) : void
plain String /// This is the text to be written to the output. ///
return void

Write() public method

This is used to write plain text to the output stream without any translation. This is used when writing the start tags and end tags, this is also used to write attribute names.
public Write ( String plain, String prefix ) : void
plain String /// This is the text to be written to the output. ///
prefix String /// This is the namespace prefix to be written. ///
return void

Write() public method

This is used to write a character to the output stream without any translation. This is used when writing the start tags and end tags, this is also used to write attribute names.
public Write ( char ch ) : void
ch char /// This is the character to be written to the output. ///
return void

WriteAttribute() public method

This is used to write a name value attribute pair. If the last tag written was not a start tag then this throws an exception. All attribute values written are enclosed in double quotes.
public WriteAttribute ( String name, String value, String prefix ) : void
name String /// This is the name of the attribute to be written. ///
value String /// This is the value to assigne to the attribute. ///
prefix String
return void

WriteComment() public method

This is used to write any comments that have been set. The comment will typically be written at the start of an element to describe the purpose of the element or include debug data that can be used to determine any issues in serialization.
public WriteComment ( String comment ) : void
comment String /// This is the comment that is to be written. ///
return void

WriteEnd() public method

This is used to write an end element tag to the writer. This will close the element with a short /> if the last tag written was a start tag. However if an end tag or some text was written then a full end tag is written.
public WriteEnd ( String name, String prefix ) : void
name String /// This is the name of the element to be closed. ///
prefix String
return void

WriteNamespace() public method

This is used to write the namespace to the element. This will write the special attribute using the prefix and reference specified. This will escape the reference if it is required.
public WriteNamespace ( String reference, String prefix ) : void
reference String /// This is the namespace URI reference to use. ///
prefix String /// This is the prefix to used for the namespace. ///
return void

WriteProlog() public method

This is used to write a prolog to the specified output. This is only written if the specified Format object has been given a non null prolog. If no prolog is specified then no prolog is written to the generated XML.
public WriteProlog ( ) : void
return void

WriteStart() public method

This method is used to write a start tag for an element. If a start tag was written before this then it is closed. Before the start tag is written an indent is generated and placed in front of the tag, this is done for all but the first start tag.
public WriteStart ( String name, String prefix ) : void
name String /// This is the name of the start tag to be written. ///
prefix String
return void

WriteText() public method

This is used to write the specified text value to the writer. If the last tag written was a start tag then it is closed. By default this will escape any illegal XML characters.
public WriteText ( String text ) : void
text String /// This is the text to write to the output. ///
return void

WriteText() public method

This is used to write the specified text value to the writer. If the last tag written was a start tag then it is closed. This will use the output mode specified.
public WriteText ( String text, Mode mode ) : void
text String /// This is the text to write to the output. ///
mode Mode
return void