Classes | Public Types | Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | Private Member Functions

XMLStorage::XMLStreamWriter Class Reference

XMLStreamWriter is used to Write XML streams in XMLStorage. More...

Collaboration diagram for XMLStorage::XMLStreamWriter:
Collaboration graph
[legend]

List of all members.

Classes

class  StackEntry
 StackEntry is used to hold state information when moving between nodes. More...

Public Types

enum  PRETTY_FLAGS { PRETTY_PLAIN = 0, PRETTY_LINEFEED = 1, PRETTY_INDENT = 2 }

Public Member Functions

 XMLStreamWriter (TextWriter w)
 XMLStreamWriter (string path)
 XMLStreamWriter (TextWriter w, PRETTY_FLAGS pretty, XMLHeader header)
 XMLStreamWriter (string path, PRETTY_FLAGS pretty, XMLHeader header)
void close ()
void create (string name)
 create node and move to it
bool back ()
 go back to previous position
void put (string attrName, Object value)
 attribute setting
void put (string attrName, string value)
 attribute setting
void setContent (string s)
void setContent (string s, bool cdata)

Protected Types

enum  WRITESTATE { NOTHING = 0, ATTRIBUTES = 2, PRE_CLOSED = 3, POST = 5 }

Protected Member Functions

void closePre (StackEntry entry)
void writePre (StackEntry entry)
void writeAttributes (StackEntry entry)
void writePost (StackEntry entry)

Protected Attributes

TextWriter _out
PRETTY_FLAGS _pretty
Stack< StackEntry_stack = new Stack<StackEntry>()

Private Member Functions

void init (TextWriter w, PRETTY_FLAGS pretty, XMLHeader header)

Detailed Description

XMLStreamWriter is used to Write XML streams in XMLStorage.

Definition at line 49 of file XMLStreamWriter.cs.


Member Enumeration Documentation

Enumerator:
PRETTY_PLAIN 
PRETTY_LINEFEED 
PRETTY_INDENT 

Definition at line 52 of file XMLStreamWriter.cs.

                             {
        PRETTY_PLAIN    = 0,
        PRETTY_LINEFEED = 1,
        PRETTY_INDENT   = 2
    };
Enumerator:
NOTHING 
ATTRIBUTES 
PRE_CLOSED 
POST 

Definition at line 162 of file XMLStreamWriter.cs.

                              {
        NOTHING     = 0,
        /*PRE       = 1,*/
        ATTRIBUTES  = 2,
        PRE_CLOSED  = 3,
        /*CONTENT   = 4,*/
        POST        = 5
    }

Constructor & Destructor Documentation

XMLStorage::XMLStreamWriter::XMLStreamWriter ( TextWriter  w ) [inline]

Definition at line 58 of file XMLStreamWriter.cs.

References init().

    {
        init(w, PRETTY_FLAGS.PRETTY_INDENT, new XMLHeader());
    }

Here is the call graph for this function:

XMLStorage::XMLStreamWriter::XMLStreamWriter ( string  path ) [inline]

Definition at line 63 of file XMLStreamWriter.cs.

References init().

    {
        init(new StreamWriter(path), PRETTY_FLAGS.PRETTY_INDENT, new XMLHeader());
    }

Here is the call graph for this function:

XMLStorage::XMLStreamWriter::XMLStreamWriter ( TextWriter  w,
PRETTY_FLAGS  pretty,
XMLHeader  header 
) [inline]

Definition at line 68 of file XMLStreamWriter.cs.

References init().

    {
        init(w, pretty, header);
    }

Here is the call graph for this function:

XMLStorage::XMLStreamWriter::XMLStreamWriter ( string  path,
PRETTY_FLAGS  pretty,
XMLHeader  header 
) [inline]

Definition at line 73 of file XMLStreamWriter.cs.

References init().

    {
        init(new StreamWriter(path), pretty, header);
    }

Here is the call graph for this function:


Member Function Documentation

bool XMLStorage::XMLStreamWriter::back (  ) [inline]

go back to previous position

Definition at line 113 of file XMLStreamWriter.cs.

References _stack, and writePost().

Referenced by WriterTest::testWriter().

    {
        if (_stack.Count > 0) {
            writePost((StackEntry)_stack.Peek());

            _stack.Pop();

            return true;
        } else
            return false;
    }

Here is the call graph for this function:

void XMLStorage::XMLStreamWriter::close (  ) [inline]

Definition at line 86 of file XMLStreamWriter.cs.

References _out.

Referenced by WriterTest::testWriter().

    {
        _out.Write('\n');
        _out.Close();
    }
void XMLStorage::XMLStreamWriter::closePre ( StackEntry  entry ) [inline, protected]

Definition at line 196 of file XMLStreamWriter.cs.

References _out, and XMLStorage::XMLStreamWriter::StackEntry::_state.

Referenced by create(), and writePost().

    {
        _out.Write('>');

        entry._state = WRITESTATE.PRE_CLOSED;
    }
void XMLStorage::XMLStreamWriter::create ( string  name ) [inline]

create node and move to it

Definition at line 93 of file XMLStreamWriter.cs.

References XMLStorage::XMLStreamWriter::StackEntry::_children, _stack, XMLStorage::XMLStreamWriter::StackEntry::_state, closePre(), writeAttributes(), and writePre().

Referenced by WriterTest::testWriter().

    {
        if (_stack.Count > 0) {
            StackEntry last = (StackEntry) _stack.Peek();

            if (last._state < WRITESTATE.PRE_CLOSED) {
                writeAttributes(last);
                closePre(last);
            }

            last._children = true;
        }

        StackEntry entry = new StackEntry(name);
        _stack.Push(entry);

        writePre(entry);
    }

Here is the call graph for this function:

void XMLStorage::XMLStreamWriter::init ( TextWriter  w,
PRETTY_FLAGS  pretty,
XMLHeader  header 
) [inline, private]

Definition at line 78 of file XMLStreamWriter.cs.

References _out, _pretty, and XMLStorage::XMLHeader::print().

Referenced by XMLStreamWriter().

    {
        _out = w;
        _pretty = pretty;

        header.print(_out, false);
    }

Here is the call graph for this function:

void XMLStorage::XMLStreamWriter::put ( string  attrName,
Object  value 
) [inline]

attribute setting

Definition at line 126 of file XMLStreamWriter.cs.

References _stack.

Referenced by WriterTest::testWriter().

    {
        if (_stack.Count > 0) {
            Dictionary<string, string> attributes = ((StackEntry)_stack.Peek())._attributes;

            if (value != null)
                attributes.Add(attrName, value.ToString());
            else
                attributes.Remove(attrName);
        }
    }
void XMLStorage::XMLStreamWriter::put ( string  attrName,
string  value 
) [inline]

attribute setting

Definition at line 139 of file XMLStreamWriter.cs.

References _stack.

    {
        if (_stack.Count > 0) {
            Dictionary<string, string> attributes = ((StackEntry)_stack.Peek())._attributes;

            if (value != null)
                attributes.Add(attrName, value);
            else
                attributes.Remove(attrName);
        }
    }
void XMLStorage::XMLStreamWriter::setContent ( string  s,
bool  cdata 
) [inline]

Definition at line 156 of file XMLStreamWriter.cs.

References _stack, and XMLStorage::XMLHelper::encodeXMLString().

    {
        if (_stack.Count > 0)
            ((StackEntry)_stack.Peek())._content = s!=null? XMLHelper.encodeXMLString(s, cdata): "";
    }

Here is the call graph for this function:

void XMLStorage::XMLStreamWriter::setContent ( string  s ) [inline]

Definition at line 151 of file XMLStreamWriter.cs.

Referenced by WriterTest::testWriter().

    {
        setContent(s, false);
    }
void XMLStorage::XMLStreamWriter::writeAttributes ( StackEntry  entry ) [inline, protected]

Definition at line 216 of file XMLStreamWriter.cs.

References _out, and XMLStorage::XMLHelper::encodeXMLString().

Referenced by create(), and writePost().

    {
        foreach(KeyValuePair<string, string> it in entry._attributes)
            _out.Write(" " + XMLHelper.encodeXMLString(it.Key) +
                       "=\"" + XMLHelper.encodeXMLString(it.Value) + "\"");

        entry._state = WRITESTATE.ATTRIBUTES;
    }

Here is the call graph for this function:

void XMLStorage::XMLStreamWriter::writePost ( StackEntry  entry ) [inline, protected]

Definition at line 225 of file XMLStreamWriter.cs.

References XMLStorage::XMLStreamWriter::StackEntry::_children, XMLStorage::XMLStreamWriter::StackEntry::_content, XMLStorage::XMLStreamWriter::StackEntry::_nodeName, _out, _pretty, _stack, XMLStorage::XMLStreamWriter::StackEntry::_state, closePre(), XMLStorage::XMLHelper::encodeXMLString(), writeAttributes(), and XMLStorage::XMLNode::XML_INDENT_SPACE.

Referenced by back().

    {
        if (entry._state < WRITESTATE.ATTRIBUTES)
            writeAttributes(entry);

        if (entry._children || entry._content.Length>0) {
            if (entry._state < WRITESTATE.PRE_CLOSED)
                closePre(entry);

            _out.Write(entry._content);
            //entry._state = WRITESTATE.CONTENT;

            if (_pretty>=PRETTY_FLAGS.PRETTY_LINEFEED && entry._content.Length==0)
                _out.Write('\n');

            if (_pretty==PRETTY_FLAGS.PRETTY_INDENT && entry._content.Length==0)
                for(int i=_stack.Count; --i>0; )
                    _out.Write(XMLNode.XML_INDENT_SPACE);

            _out.Write("</" + XMLHelper.encodeXMLString(entry._nodeName) + ">");
        } else {
            _out.Write("/>");
        }

        entry._state = WRITESTATE.POST;
    }

Here is the call graph for this function:

void XMLStorage::XMLStreamWriter::writePre ( StackEntry  entry ) [inline, protected]

Definition at line 203 of file XMLStreamWriter.cs.

References XMLStorage::XMLStreamWriter::StackEntry::_nodeName, _out, _pretty, _stack, XMLStorage::XMLHelper::encodeXMLString(), and XMLStorage::XMLNode::XML_INDENT_SPACE.

Referenced by create().

    {
        if (_pretty >= PRETTY_FLAGS.PRETTY_LINEFEED)
            _out.Write('\n');

        if (_pretty == PRETTY_FLAGS.PRETTY_INDENT)
            for(int i=_stack.Count; --i>0; )
                _out.Write(XMLNode.XML_INDENT_SPACE);

        _out.Write("<" + XMLHelper.encodeXMLString(entry._nodeName));
        //entry._state = WRITESTATE.PRE;
    }

Here is the call graph for this function:


Member Data Documentation

TextWriter XMLStorage::XMLStreamWriter::_out [protected]

Definition at line 171 of file XMLStreamWriter.cs.

Referenced by close(), closePre(), init(), writeAttributes(), writePost(), and writePre().

Definition at line 172 of file XMLStreamWriter.cs.

Referenced by init(), writePost(), and writePre().

Stack<StackEntry> XMLStorage::XMLStreamWriter::_stack = new Stack<StackEntry>() [protected]

Definition at line 192 of file XMLStreamWriter.cs.

Referenced by back(), create(), put(), setContent(), writePost(), and writePre().


The documentation for this class was generated from the following file: