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

XMLStorage::XMLNode Class Reference

XMLNode is the in memory representation of an XML node in the XMLStorage library. More...

Inheritance diagram for XMLStorage::XMLNode:
Inheritance graph
[legend]
Collaboration diagram for XMLStorage::XMLNode:
Collaboration graph
[legend]

List of all members.

Classes

class  Children
 Children contains the list of immediate child nodes. More...

Public Types

enum  WRITE_MODE { FORMAT_SMART, FORMAT_ORIGINAL, FORMAT_PRETTY }

Public Member Functions

 XMLNode (string name)
 XMLNode (string name, string leading)
 XMLNode (XMLNode other)
override string getName ()
override string ToString ()
void clear ()
void assign (XMLNode other)
void addChild (XMLNode child)
 add a new child node
override string get (string attrName)
 read only access to an attribute
override string get (string attrName, string def)
 read only access to an attribute with default value
void put (string attrName, string value)
 Write access to an attribute.
string getSubattrib (string nodeName, string attrName)
 convenient value access in children node
string getSubattrib (string nodeName, string attrName, int n)
void putSubattrib (string nodeName, string attrName, string value)
 convenient storage of distinct values in children node
void putSubattrib (string nodeName, string attrName, string value, int n)
Children getChildren ()
override string getContent ()
void setContent (string s)
void setContent (string s, bool cdata)
virtual void write (TextWriter w)
virtual void write (TextWriter w, WRITE_MODE mode)
void write (TextWriter w, WRITE_MODE mode, int indent)
 Write node with children tree.
XMLNode getFirstChild ()
XMLNode find (string nodeName)
 Find a children node by name.
XMLNode find (string nodeName, int n)
 Find the n'th children node with tag nodeName.
XMLNode find (string nodeName, string attrName, string attrValue)
 Search matching child node identified by key name and an attribute value.
XMLNode find (string nodeName, string attrName, string attrValue, int n)
 Search matching child node identified by key name and an attribute value.
XMLNode findRelative (XPath xpath)
 XPath find function.
AbstractXMLNode createRelative (XPath xpath)
 relative XPath create function
XMLInt getInt (string attrName)
XMLInt getInt (string attrName, int def)
XMLDecimal getNumber (string attrName)
XMLDecimal getNumber (string attrName, decimal def)
XMLBool getBool (string attrName)
XMLBool getBool (string attrName, bool def)
XMLString getString (string attrName)
XMLString getString (string attrName, string def)
void setAttributes (XmlReader reader)
bool hasAttributes ()

Public Attributes

string _leading = ""
string _endLeading = ""
string _trailing = ""

Static Public Attributes

static string XML_INDENT_SPACE = " "

Protected Member Functions

void writeWorker (TextWriter w, int indent)
 Write node with children tree using original white space.
void prettyWriteWorker (TextWriter w, int indent)
void smartWriteWorker (TextWriter w, int indent)

Protected Attributes

string _name
Children _children = new Children()
Dictionary< string, string > _attributes = new Dictionary<string, string>()

Detailed Description

XMLNode is the in memory representation of an XML node in the XMLStorage library.

Definition at line 49 of file XMLNode.cs.


Member Enumeration Documentation

Enumerator:
FORMAT_SMART 
FORMAT_ORIGINAL 

preserve original white space and comments if present; pretty print otherwise

FORMAT_PRETTY 

Write XML stream preserving original white space and comments.

pretty print node to stream without preserving original white space

Definition at line 239 of file XMLNode.cs.

                           {
//TODO  FORMAT_PLAIN,       /// Write XML without any white space
        FORMAT_SMART,       /// preserve original white space and comments if present; pretty print otherwise
        FORMAT_ORIGINAL,    /// Write XML stream preserving original white space and comments
        FORMAT_PRETTY       /// pretty print node to stream without preserving original white space
    };

Constructor & Destructor Documentation

XMLStorage::XMLNode::XMLNode ( string  name ) [inline]

Definition at line 51 of file XMLNode.cs.

References _name.

Referenced by XMLStorage::XMLNode::Children::assign(), createRelative(), and putSubattrib().

    {
        _name = name;
    }
XMLStorage::XMLNode::XMLNode ( string  name,
string  leading 
) [inline]

Definition at line 56 of file XMLNode.cs.

References _leading, and _name.

    {
         _name = name;
         _leading = leading;
    }
XMLStorage::XMLNode::XMLNode ( XMLNode  other ) [inline]

Definition at line 62 of file XMLNode.cs.

References assign().

    {
        assign(other);
    }

Here is the call graph for this function:


Member Function Documentation

void XMLStorage::XMLNode::addChild ( XMLNode  child ) [inline]

add a new child node

Definition at line 135 of file XMLNode.cs.

References _children.

Referenced by XMLStorage::XMLPos::addDown(), createRelative(), and putSubattrib().

    {
        _children.AddLast(child);
    }
void XMLStorage::XMLNode::assign ( XMLNode  other ) [inline]

Definition at line 122 of file XMLNode.cs.

References XMLStorage::AbstractXMLNode::_attributes, _children, XMLStorage::AbstractXMLNode::_content, _endLeading, _leading, _trailing, and XMLStorage::XMLNode::Children::assign().

Referenced by XMLNode().

    {
        _children.assign(other._children);

        _attributes = (Dictionary<string, string>) other._attributes;//@@ .clone();

        _leading = other._leading;
        _content = other._content;
        _endLeading = other._endLeading;
        _trailing = other._trailing;
    }

Here is the call graph for this function:

void XMLStorage::XMLNode::clear (  ) [inline]
AbstractXMLNode XMLStorage::XMLNode::createRelative ( XPath  xpath ) [inline]

relative XPath create function

Definition at line 363 of file XMLNode.cs.

References XMLStorage::XPathElement::_childName, XMLStorage::XPathElement::_mAttrAndAttr, addChild(), XMLStorage::XPathElement::find(), put(), and XMLNode().

    {
        XMLNode node = this;

        foreach(XPathElement elem in xpath) {
            XMLNode child = elem.find(node);

            if (child == null) {
                child = new XMLNode(elem._childName);
                node.addChild(child);

                foreach(KeyValuePair<string, string> it in elem._mAttrAndAttr)
                    put(it.Key, it.Value);
            }

            node = child;
        }

        return node;
    }

Here is the call graph for this function:

XMLNode XMLStorage::XMLNode::find ( string  nodeName ) [inline]

Find a children node by name.

Parameters:
nodeName
Returns:

Definition at line 287 of file XMLNode.cs.

References _children, and _name.

Referenced by getSubattrib(), and putSubattrib().

    {
        foreach(XMLNode child in _children)
            if (child._name == nodeName)
                return child;

        return null;
    }
XMLNode XMLStorage::XMLNode::find ( string  nodeName,
int  n 
) [inline]

Find the n'th children node with tag nodeName.

Parameters:
nodeName
n
Returns:

Definition at line 302 of file XMLNode.cs.

References _children, and _name.

    {
        foreach(XMLNode child in _children)
            if (child._name == nodeName)
                if (n-- == 0)
                    return child;

        return null;
    }
XMLNode XMLStorage::XMLNode::find ( string  nodeName,
string  attrName,
string  attrValue 
) [inline]

Search matching child node identified by key name and an attribute value.

Parameters:
nodeName
attrName
attrValue
Returns:
XMLNode

Definition at line 319 of file XMLNode.cs.

References _children, _name, and get().

    {
        foreach(XMLNode child in _children)
            if (child._name==nodeName && child.get(attrName)==attrValue)
                return child;

        return null;
    }

Here is the call graph for this function:

XMLNode XMLStorage::XMLNode::find ( string  nodeName,
string  attrName,
string  attrValue,
int  n 
) [inline]

Search matching child node identified by key name and an attribute value.

Parameters:
nodeName
attrName
attrValue
n
Returns:
XMLNode

Definition at line 336 of file XMLNode.cs.

References _children, _name, and get().

    {
        foreach(XMLNode node in _children)
            if (node._name==nodeName && node.get(attrName)==attrValue)
                if (n-- == 0)
                    return node;

        return null;
    }

Here is the call graph for this function:

XMLNode XMLStorage::XMLNode::findRelative ( XPath  xpath ) [inline]

XPath find function.

Definition at line 347 of file XMLNode.cs.

References XMLStorage::XPathElement::find().

Referenced by XMLStorage::XMLPos::go().

    {
        XMLNode node = this;

        foreach(XPathElement xelem in xpath)
        {
            node = xelem.find(node);

            if (node == null)
                break;
        }

        return node;
    }

Here is the call graph for this function:

override string XMLStorage::XMLNode::get ( string  attrName ) [inline, virtual]
override string XMLStorage::XMLNode::get ( string  attrName,
string  def 
) [inline, virtual]

read only access to an attribute with default value

Implements XMLStorage::AbstractXMLNode.

Definition at line 152 of file XMLNode.cs.

References XMLStorage::AbstractXMLNode::_attributes.

    {
        string found;

        if (_attributes.TryGetValue(attrName, out found))
            return found;
        else
            return def;
    }
XMLBool XMLStorage::AbstractXMLNode::getBool ( string  attrName ) [inline, inherited]

Definition at line 85 of file AbstractXMLNode.cs.

    {
        return new XMLBool(this, attrName);
    }
XMLBool XMLStorage::AbstractXMLNode::getBool ( string  attrName,
bool  def 
) [inline, inherited]

Definition at line 89 of file AbstractXMLNode.cs.

    {
        return new XMLBool(this, attrName, def);
    }
Children XMLStorage::XMLNode::getChildren (  ) [inline]
override string XMLStorage::XMLNode::getContent (  ) [inline, virtual]

Implements XMLStorage::AbstractXMLNode.

Definition at line 224 of file XMLNode.cs.

References XMLStorage::AbstractXMLNode::_content, and XMLStorage::XMLHelper::decodeXMLString().

Referenced by XMLStorage::XMLPos::getContent().

    {
        return XMLHelper.decodeXMLString(_content);
    }

Here is the call graph for this function:

XMLNode XMLStorage::XMLNode::getFirstChild (  ) [inline]

Definition at line 274 of file XMLNode.cs.

References _children.

Referenced by XMLStorage::XMLPos::goDown().

    {
        if (_children.Count > 0)
            return _children.First.Value;
        else
            return null;
    }
XMLInt XMLStorage::AbstractXMLNode::getInt ( string  attrName,
int  def 
) [inline, inherited]

Definition at line 71 of file AbstractXMLNode.cs.

    {
        return new XMLInt(this, attrName, def);
    }
XMLInt XMLStorage::AbstractXMLNode::getInt ( string  attrName ) [inline, inherited]

Definition at line 67 of file AbstractXMLNode.cs.

    {
        return new XMLInt(this, attrName);
    }
override string XMLStorage::XMLNode::getName (  ) [inline, virtual]

Implements XMLStorage::AbstractXMLNode.

Definition at line 69 of file XMLNode.cs.

References _name.

Referenced by XMLStorage::XMLChildrenFilter::filterChildren().

    {
        return _name;
    }
XMLDecimal XMLStorage::AbstractXMLNode::getNumber ( string  attrName ) [inline, inherited]

Definition at line 76 of file AbstractXMLNode.cs.

    {
        return new XMLDecimal(this, attrName);
    }
XMLDecimal XMLStorage::AbstractXMLNode::getNumber ( string  attrName,
decimal  def 
) [inline, inherited]

Definition at line 80 of file AbstractXMLNode.cs.

    {
        return new XMLDecimal(this, attrName, def);
    }
XMLString XMLStorage::AbstractXMLNode::getString ( string  attrName ) [inline, inherited]

Definition at line 94 of file AbstractXMLNode.cs.

    {
        return new XMLString(this, attrName);
    }
XMLString XMLStorage::AbstractXMLNode::getString ( string  attrName,
string  def 
) [inline, inherited]

Definition at line 98 of file AbstractXMLNode.cs.

    {
        return new XMLString(this, attrName, def);
    }
string XMLStorage::XMLNode::getSubattrib ( string  nodeName,
string  attrName 
) [inline]

convenient value access in children node

Definition at line 174 of file XMLNode.cs.

References find(), and XMLStorage::AbstractXMLNode::get().

    {
        AbstractXMLNode node = find(nodeName);

        if (node != null)
            return node.get(attrName);
        else
            return "";
    }

Here is the call graph for this function:

string XMLStorage::XMLNode::getSubattrib ( string  nodeName,
string  attrName,
int  n 
) [inline]

Definition at line 184 of file XMLNode.cs.

References find(), and XMLStorage::AbstractXMLNode::get().

    {
        AbstractXMLNode node = find(nodeName, n);

        if (node != null)
            return node.get(attrName);
        else
            return "";
    }

Here is the call graph for this function:

bool XMLStorage::AbstractXMLNode::hasAttributes (  ) [inline, inherited]
void XMLStorage::XMLNode::prettyWriteWorker ( TextWriter  w,
int  indent 
) [inline, protected]

Definition at line 428 of file XMLNode.cs.

References XMLStorage::AbstractXMLNode::_attributes, _children, XMLStorage::AbstractXMLNode::_content, _name, XMLStorage::XMLHelper::encodeXMLString(), prettyWriteWorker(), and XML_INDENT_SPACE.

Referenced by prettyWriteWorker(), and write().

    {
        for(int i=indent; i-->0; )
            w.Write(XML_INDENT_SPACE);

        w.Write('<');
        w.Write(XMLHelper.encodeXMLString(_name));

        foreach(KeyValuePair<string,string> it in _attributes) {
            string attrValue = it.Value;

            if (attrValue != null) {
                w.Write(' ');
                w.Write(XMLHelper.encodeXMLString(it.Key));
                w.Write("=\"");
                w.Write(XMLHelper.encodeXMLString(attrValue));
                w.Write("\"");
            }
        }

        if (_children.Count>0 || _content.Length>0) {
            w.Write(">\n");

            foreach(XMLNode child in _children)
                child.prettyWriteWorker(w, indent+1);

            for(int i=indent; i-->0; )
                w.Write(XML_INDENT_SPACE);

            w.Write("</");
            w.Write(XMLHelper.encodeXMLString(_name));
            w.Write(">\n");
        } else
            w.Write("/>\n");
    }

Here is the call graph for this function:

void XMLStorage::XMLNode::put ( string  attrName,
string  value 
) [inline]
void XMLStorage::XMLNode::putSubattrib ( string  nodeName,
string  attrName,
string  value 
) [inline]

convenient storage of distinct values in children node

Definition at line 195 of file XMLNode.cs.

References addChild(), find(), put(), and XMLNode().

Referenced by XMLStorage::XMLPos::putSubattrib().

    {
        XMLNode node = find(nodeName);

        if (node == null) {
            node = new XMLNode(nodeName);
            addChild(node);
        }

        node.put(attrName, value);
    }

Here is the call graph for this function:

void XMLStorage::XMLNode::putSubattrib ( string  nodeName,
string  attrName,
string  value,
int  n 
) [inline]

Definition at line 207 of file XMLNode.cs.

References addChild(), find(), put(), and XMLNode().

    {
        XMLNode node = find(nodeName, n);

        if (node == null) {
            node = new XMLNode(nodeName);
            addChild(node);
        }

        node.put(attrName, value);
    }

Here is the call graph for this function:

void XMLStorage::AbstractXMLNode::setAttributes ( XmlReader  reader ) [inline, inherited]

Definition at line 103 of file AbstractXMLNode.cs.

References XMLStorage::AbstractXMLNode::_attributes.

Referenced by XMLStorage::XMLStreamReader::startElement(), and XMLStorage::XMLDocReader::startElement().

    {
        while(reader.MoveToNextAttribute()) {
            string attrNS = reader.NamespaceURI;
            string attrName = reader.Name;
            string attrValue = reader.Value;

            if (attrNS.Length > 0)
                attrName = attrNS + ":" + attrName;

            _attributes.Add(attrName, attrValue);
        }
    }
void XMLStorage::XMLNode::setContent ( string  s,
bool  cdata 
) [inline]

Definition at line 234 of file XMLNode.cs.

References XMLStorage::AbstractXMLNode::_content, and XMLStorage::XMLHelper::encodeXMLString().

    {
        _content = XMLHelper.encodeXMLString(s, cdata);
    }

Here is the call graph for this function:

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

Definition at line 229 of file XMLNode.cs.

Referenced by XMLStorage::XMLPos::setContent().

    {
        setContent(s, false);
    }
void XMLStorage::XMLNode::smartWriteWorker ( TextWriter  w,
int  indent 
) [inline, protected]

Definition at line 464 of file XMLNode.cs.

References XMLStorage::AbstractXMLNode::_attributes, _children, XMLStorage::AbstractXMLNode::_content, _endLeading, _leading, _name, _trailing, XMLStorage::XMLHelper::encodeXMLString(), and XML_INDENT_SPACE.

Referenced by write().

    {
        if (_leading.Length == 0)
            for(int i=indent; i-->0; )
                w.Write(XML_INDENT_SPACE);
        else
            w.Write(_leading);

        w.Write('<');
        w.Write(XMLHelper.encodeXMLString(_name));

        foreach(KeyValuePair<string,string> it in _attributes) {
            string attrValue = it.Value;

            if (attrValue != null) {
                w.Write(' ');
                w.Write(XMLHelper.encodeXMLString(it.Key));
                w.Write("=\"");
                w.Write(XMLHelper.encodeXMLString(attrValue));
                w.Write("\"");
            }
        }

        if (_children.Count==0 && _content.Length==0)
            w.Write("/>");
        else {
            w.Write('>');

            if (_content.Length == 0)
                w.Write('\n');
            else
                w.Write(_content);

            LinkedListNode<XMLNode> it = _children.First;

            if (it != null) {
                for( ; it != null; it = it.Next )
                    it.Value.smartWriteWorker( w, indent + 1 );

                if (_endLeading.Length == 0)
                    for(int i=indent; i-->0; )
                        w.Write(XML_INDENT_SPACE);
                else
                    w.Write(_endLeading);
            } else
                w.Write(_endLeading);

            w.Write("</");
            w.Write(XMLHelper.encodeXMLString(_name));
            w.Write('>');
        }

        if (_trailing.Length == 0)
            w.Write('\n');
        else
            w.Write(_trailing);
    }

Here is the call graph for this function:

override string XMLStorage::XMLNode::ToString (  ) [inline, virtual]

Implements XMLStorage::AbstractXMLNode.

Definition at line 74 of file XMLNode.cs.

References _name.

Referenced by XMLStorage::XMLPos::ToString().

    {
        return _name;
    }
void XMLStorage::XMLNode::write ( TextWriter  w,
WRITE_MODE  mode,
int  indent 
) [inline]

Write node with children tree.

Definition at line 257 of file XMLNode.cs.

References prettyWriteWorker(), smartWriteWorker(), and writeWorker().

    {
        switch(mode) {
          case WRITE_MODE.FORMAT_PRETTY:
            prettyWriteWorker(w, indent);
            break;

          case WRITE_MODE.FORMAT_ORIGINAL:
            writeWorker(w, indent);
            break;

          default: // FORMAT_SMART
            smartWriteWorker(w, indent);
            break;
        }
    }

Here is the call graph for this function:

virtual void XMLStorage::XMLNode::write ( TextWriter  w,
WRITE_MODE  mode 
) [inline, virtual]

Reimplemented in XMLStorage::XMLDoc.

Definition at line 251 of file XMLNode.cs.

References write().

    {
        write(w, mode, 0);
    }

Here is the call graph for this function:

virtual void XMLStorage::XMLNode::write ( TextWriter  w ) [inline, virtual]

Reimplemented in XMLStorage::XMLDoc.

Definition at line 246 of file XMLNode.cs.

Referenced by write().

    {
        write(w, WRITE_MODE.FORMAT_SMART, 0);
    }
void XMLStorage::XMLNode::writeWorker ( TextWriter  w,
int  indent 
) [inline, protected]

Write node with children tree using original white space.

Parameters:
o
indent

Definition at line 390 of file XMLNode.cs.

References XMLStorage::AbstractXMLNode::_attributes, _children, XMLStorage::AbstractXMLNode::_content, _endLeading, _leading, _name, _trailing, XMLStorage::XMLHelper::encodeXMLString(), and writeWorker().

Referenced by write(), and writeWorker().

    {
        w.Write(_leading);
        w.Write('<');
        w.Write(XMLHelper.encodeXMLString(_name));

        foreach(KeyValuePair<string,string> it in _attributes) {
            string attrValue = it.Value;

            if (attrValue != null) {
                w.Write(' ');
                w.Write(XMLHelper.encodeXMLString(it.Key));
                w.Write("=\"");
                w.Write(XMLHelper.encodeXMLString(attrValue));
                w.Write("\"");
            }
        }


        if (_children.Count>0 || _content.Length>0) {
            w.Write('>');
            w.Write(_content);

            foreach(XMLNode child in _children)
                child.writeWorker(w, indent+1);

            w.Write(_endLeading);
            w.Write("</");
            w.Write(XMLHelper.encodeXMLString(_name));
            w.Write('>');
        } else
            w.Write("/>");

        w.Write(_trailing);
    }

Here is the call graph for this function:


Member Data Documentation

Dictionary<string, string> XMLStorage::AbstractXMLNode::_attributes = new Dictionary<string, string>() [protected, inherited]

Definition at line 105 of file XMLNode.cs.

Referenced by assign(), clear(), smartWriteWorker(), writeWorker(), and XMLNode().

string XMLStorage::XMLNode::_name [protected]

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