Public Member Functions | Protected Member Functions | Protected Attributes

XMLStorage::XMLPos Class Reference

XMLPos is the iterator for XML trees in XMLStorage. More...

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

List of all members.

Public Member Functions

 XMLPos (XMLNode root)
 Construct an XMLPos, which points to the given XMLNode.
 XMLPos (XMLPos other)
 Construct an XMLPos as copy of another.
 XMLPos (XMLPos other, string nodeName)
 Create XML tree iterator positioned at subnode node_name of current other position.
 XMLPos (XMLPos other, string nodeName, string attrName, string attrValue)
 Create XML tree iterator positioned at subnode node_name with attribute attrName and attribute value attrValue.
XMLNode cur ()
 Return the current node.
string get (string attrName)
 Return the value of an attribute in the current node or "".
string get (string attrName, string def)
 Return the value of an attribute in the current node or a default value.
void put (string attrName, string value)
 Set an attribute value.
void addDown (XMLNode child)
 Insert children when building tree.
bool back ()
 Go back to previous position.
bool goDown ()
 Go down to first child.
bool goDown (string child_name)
 Search for child and go down.
bool goDown (string child_name, int child_idx)
 Search for child and go down.
bool go (string path)
 Move X-Path like to position in XML tree.
bool go (XPath xpath)
 Move X-Path like to position in XML tree.
void create (string name)
 Create node and move to it.
void smartCreate (string child_name)
 Create node if not already existing and move to it.
void smartCreate (string name, string attrName, string attrValue)
 Search matching child node identified by key name and an attribute value.
string getContent ()
void setContent (string s)
void setContent (string s, bool cdata)
override string ToString ()
 Return the name oif the current node.
void putSubattrib (string nodeName, string attrName, string value)
 Set an attribute in a subnode.

Protected Member Functions

void goTo (XMLNode child)
 Go to the specified node.

Protected Attributes

XMLNode _root
XMLNode _cur
Stack< XMLNode_stack = new Stack<XMLNode>()

Detailed Description

XMLPos is the iterator for XML trees in XMLStorage.

Author:
Martin Fuchs

Definition at line 48 of file XMLPos.cs.


Constructor & Destructor Documentation

XMLStorage::XMLPos::XMLPos ( XMLNode  root ) [inline]

Construct an XMLPos, which points to the given XMLNode.

Parameters:
rootroot node

Definition at line 54 of file XMLPos.cs.

References _cur, and _root.

    {
        _root = root;
        _cur = root;
    }
XMLStorage::XMLPos::XMLPos ( XMLPos  other ) [inline]

Construct an XMLPos as copy of another.

Parameters:
otherXMLPos original

Definition at line 64 of file XMLPos.cs.

References _cur, and _root.

    {
        _root = other._root;
        _cur = other._cur;
        // don't copy _stack
    }
XMLStorage::XMLPos::XMLPos ( XMLPos  other,
string  nodeName 
) [inline]

Create XML tree iterator positioned at subnode node_name of current other position.

Parameters:
otherposition to be copied
nodeNamenew node name

Definition at line 76 of file XMLPos.cs.

References _cur, _root, and smartCreate().

    {
        _root = other._root;
        _cur = other._cur;
        // don't copy _stack
        smartCreate(nodeName);
    }

Here is the call graph for this function:

XMLStorage::XMLPos::XMLPos ( XMLPos  other,
string  nodeName,
string  attrName,
string  attrValue 
) [inline]

Create XML tree iterator positioned at subnode node_name with attribute attrName and attribute value attrValue.

See also:
XMLPos.smart_create
Parameters:
otherposition to be copied
nodeNamenew node name
attrNameattribute name
attrValueattribute value

Definition at line 93 of file XMLPos.cs.

References _cur, _root, and smartCreate().

    {
        _root = other._root;
        _cur = other._cur;
        // don't copy _stack
        smartCreate(nodeName, attrName, attrValue);
    }

Here is the call graph for this function:


Member Function Documentation

void XMLStorage::XMLPos::addDown ( XMLNode  child ) [inline]

Insert children when building tree.

Parameters:
childnew child

Definition at line 145 of file XMLPos.cs.

References _cur, XMLStorage::XMLNode::addChild(), and goTo().

Referenced by create(), smartCreate(), and XMLStorage::XMLDocReader::startElement().

    {
        _cur.addChild(child);
        goTo(child);
    }

Here is the call graph for this function:

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

Go back to previous position.

Returns:
true if successfull

Definition at line 155 of file XMLPos.cs.

References _cur, and _stack.

Referenced by XMLStorage::XMLDocReader::endElement(), Example3::testRead(), Example2::testRead(), Example1::testRead(), Example3::testWrite(), Example2::testWrite(), and Example1::testWrite().

    {
        if (_stack.Count > 0) {
            _cur = _stack.Pop();
            return true;
        } else
            return false;
    }
void XMLStorage::XMLPos::create ( string  name ) [inline]

Create node and move to it.

Parameters:
namename of the new node

Definition at line 238 of file XMLPos.cs.

References addDown().

Referenced by Example3::testWrite(), Example2::testWrite(), Example1::testWrite(), and XMLStorage::XMLMessage::XMLMessage().

    {
        addDown(new XMLNode(name));
    }

Here is the call graph for this function:

XMLNode XMLStorage::XMLPos::cur (  ) [inline]
string XMLStorage::XMLPos::get ( string  attrName ) [inline]

Return the value of an attribute in the current node or "".

Parameters:
attrNameattribute name
Returns:
attribute value

Definition at line 115 of file XMLPos.cs.

References _cur, and XMLStorage::XMLNode::get().

Referenced by Example3::testRead(), and Example2::testRead().

    {
        return _cur.get(attrName);
    }

Here is the call graph for this function:

string XMLStorage::XMLPos::get ( string  attrName,
string  def 
) [inline]

Return the value of an attribute in the current node or a default value.

Parameters:
attrNameattribute name
defdefault value
Returns:
value

Definition at line 126 of file XMLPos.cs.

References _cur, and XMLStorage::XMLNode::get().

    {
        return _cur.get(attrName, def);
    }

Here is the call graph for this function:

string XMLStorage::XMLPos::getContent (  ) [inline]
Returns:
content string

Definition at line 280 of file XMLPos.cs.

References _cur, and XMLStorage::XMLNode::getContent().

Referenced by Example1::testRead().

    {
        return _cur.getContent();
    }

Here is the call graph for this function:

bool XMLStorage::XMLPos::go ( string  path ) [inline]

Move X-Path like to position in XML tree.

Parameters:
pathXPath expression
Returns:
true if successfull

Definition at line 211 of file XMLPos.cs.

Referenced by Example3::testRead(), Example2::testRead(), and Example1::testRead().

    {
        return go(new XPath(path));
    }
bool XMLStorage::XMLPos::go ( XPath  xpath ) [inline]

Move X-Path like to position in XML tree.

Parameters:
pathXPath objhect
Returns:
true if successfull

Definition at line 221 of file XMLPos.cs.

References XMLStorage::XPath::_absolute, _cur, _root, XMLStorage::XMLNode::findRelative(), and goTo().

    {
        XMLNode node = xpath._absolute ? _root : _cur;

        node = node.findRelative(xpath);

        if (node != null) {
            goTo(node);
            return true;
        } else
            return false;
    }

Here is the call graph for this function:

bool XMLStorage::XMLPos::goDown ( string  child_name ) [inline]

Search for child and go down.

Parameters:
child_namenode name
Returns:
true if successfull

Definition at line 184 of file XMLPos.cs.

References goDown().

    {
        return goDown(child_name, 0);
    }

Here is the call graph for this function:

bool XMLStorage::XMLPos::goDown ( string  child_name,
int  child_idx 
) [inline]

Search for child and go down.

Parameters:
child_namenode name
child_idxchild index
Returns:
true if successfull

Definition at line 195 of file XMLPos.cs.

References _cur, XMLStorage::XPathElement::find(), and goTo().

    {
        XMLNode node = new XPathElement(child_name, child_idx).find(_cur);

        if (node != null) {
            goTo(node);
            return true;
        } else
            return false;
    }

Here is the call graph for this function:

bool XMLStorage::XMLPos::goDown (  ) [inline]

Go down to first child.

Returns:
true if successfull

Definition at line 168 of file XMLPos.cs.

References _cur, XMLStorage::XMLNode::getFirstChild(), and goTo().

Referenced by goDown(), and Example1::testRead().

    {
        XMLNode node = _cur.getFirstChild();

        if (node != null) {
            goTo(node);
            return true;
        } else
            return false;
    }

Here is the call graph for this function:

void XMLStorage::XMLPos::goTo ( XMLNode  child ) [inline, protected]

Go to the specified node.

Parameters:
childnew position

Definition at line 318 of file XMLPos.cs.

References _cur, and _stack.

Referenced by addDown(), go(), goDown(), and smartCreate().

    {
        _stack.Push(_cur);
        _cur = child;
    }
void XMLStorage::XMLPos::put ( string  attrName,
string  value 
) [inline]

Set an attribute value.

Parameters:
attrNameattribute name
valuenew attribute value

Definition at line 136 of file XMLPos.cs.

References _cur, and XMLStorage::XMLNode::put().

Referenced by Example3::testWrite(), and Example2::testWrite().

    {
        _cur.put(attrName, value);
    }

Here is the call graph for this function:

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

Set an attribute in a subnode.

Parameters:
nodeNamenode name
attrNameattribute name
valueattribute value

Definition at line 330 of file XMLPos.cs.

References _cur, and XMLStorage::XMLNode::putSubattrib().

    {
        _cur.putSubattrib(nodeName, attrName, value);
    }

Here is the call graph for this function:

void XMLStorage::XMLPos::setContent ( string  s,
bool  cdata 
) [inline]
Parameters:
snew content string
cdatawrite in CDATA format if true

Definition at line 297 of file XMLPos.cs.

References _cur, and XMLStorage::XMLNode::setContent().

    {
        _cur.setContent(s, cdata);
    }

Here is the call graph for this function:

void XMLStorage::XMLPos::setContent ( string  s ) [inline]
Parameters:
snew content string

Definition at line 288 of file XMLPos.cs.

Referenced by Example1::testWrite().

    {
        setContent(s, false);
    }
void XMLStorage::XMLPos::smartCreate ( string  name,
string  attrName,
string  attrValue 
) [inline]

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

It it doesn't exist, create it.

Parameters:
namename of the new node
attrNameattribute name
attrValueattribute value

Definition at line 264 of file XMLPos.cs.

References _cur, addDown(), XMLStorage::XPathElement::find(), goTo(), and XMLStorage::XMLNode::put().

    {
        XMLNode node = new XPathElement(name, 0, attrName, attrValue).find(_cur);

        if (node != null)
            goTo(node);
        else {
            node = new XMLNode(name);
            addDown(node);
            node.put(attrName, attrValue);
        }
    }

Here is the call graph for this function:

void XMLStorage::XMLPos::smartCreate ( string  child_name ) [inline]

Create node if not already existing and move to it.

Parameters:
child_namename of the new node

Definition at line 247 of file XMLPos.cs.

References _cur, addDown(), XMLStorage::XPathElement::find(), and goTo().

Referenced by XMLPos().

    {
        XMLNode node = new XPathElement(child_name).find(_cur);

        if (node != null)
            goTo(node);
        else
            addDown(new XMLNode(child_name));
    }

Here is the call graph for this function:

override string XMLStorage::XMLPos::ToString (  ) [inline]

Return the name oif the current node.

Definition at line 305 of file XMLPos.cs.

References _cur, and XMLStorage::XMLNode::ToString().

    {
        return _cur.ToString();
    }

Here is the call graph for this function:


Member Data Documentation

Definition at line 310 of file XMLPos.cs.

Referenced by go(), and XMLPos().

Stack<XMLNode> XMLStorage::XMLPos::_stack = new Stack<XMLNode>() [protected]

Definition at line 312 of file XMLPos.cs.

Referenced by back(), and goTo().


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