Public Member Functions | Public Attributes | Private Attributes

XMLStorage::XPathElement Class Reference

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

List of all members.

Public Member Functions

 XPathElement ()
 XPathElement (string child_name)
 XPathElement (string child_name, int child_idx)
 XPathElement (string child_name, int child_idx, string attr_name, string attr_value)
int parse (string path, int idx)
XMLNode find (XMLNode node)
bool matches (AbstractXMLNode node, int[] n)

Public Attributes

string _childName
Dictionary< string, string > _mAttrAndAttr = new Dictionary<string, string>()

Private Attributes

int _childIdx

Detailed Description

Definition at line 45 of file XPathElement.cs.


Constructor & Destructor Documentation

XMLStorage::XPathElement::XPathElement (  ) [inline]

Definition at line 47 of file XPathElement.cs.

References _childIdx.

    {
        _childIdx = -1;
    }
XMLStorage::XPathElement::XPathElement ( string  child_name ) [inline]

Definition at line 52 of file XPathElement.cs.

References _childIdx, and _childName.

    {
        _childName = child_name;
        _childIdx = -1;
    }
XMLStorage::XPathElement::XPathElement ( string  child_name,
int  child_idx 
) [inline]

Definition at line 58 of file XPathElement.cs.

References _childIdx, and _childName.

    {
        _childName = child_name;
        _childIdx = child_idx;
    }
XMLStorage::XPathElement::XPathElement ( string  child_name,
int  child_idx,
string  attr_name,
string  attr_value 
) [inline]

Definition at line 64 of file XPathElement.cs.

References _childIdx, _childName, and _mAttrAndAttr.

    {
        _childName = child_name;
        _childIdx = child_idx;

        _mAttrAndAttr.Add(attr_name, attr_value);
    }

Member Function Documentation

XMLNode XMLStorage::XPathElement::find ( XMLNode  node ) [inline]

Definition at line 144 of file XPathElement.cs.

References XMLStorage::XMLNode::getChildren(), and matches().

Referenced by XMLStorage::XMLNode::createRelative(), XMLStorage::XMLNode::findRelative(), XMLStorage::XMLPos::goDown(), and XMLStorage::XMLPos::smartCreate().

    {
        int[] n = new int[] {0};    // index in array for call-by-reference matches()

        foreach(XMLNode it in node.getChildren())
            if (matches(it, n))
                return it;

        return null;
    }

Here is the call graph for this function:

bool XMLStorage::XPathElement::matches ( AbstractXMLNode  node,
int[]  n 
) [inline]

Definition at line 155 of file XPathElement.cs.

References _childIdx, _childName, _mAttrAndAttr, and XMLStorage::AbstractXMLNode::ToString().

Referenced by find(), and XMLStorage::XMLStreamReader::find().

    {
        if (node.ToString() != _childName)
            if (_childName != "*")  // use asterisk as wildcard
                return false;

        foreach(KeyValuePair<string, string> it in _mAttrAndAttr)
            if (node.get(it.Key) != it.Value)
                return false;

        if (_childIdx == -1)
            return true;
        else if (n[0]++ == _childIdx)
            return true;
        else
            return false;
    }

Here is the call graph for this function:

int XMLStorage::XPathElement::parse ( string  path,
int  idx 
) [inline]

Definition at line 78 of file XPathElement.cs.

References _childIdx, _childName, _mAttrAndAttr, and XMLStorage::XMLHelper::unescape().

Referenced by XMLStorage::XPath::init().

    {
        int f = path.IndexOf('/', idx);
        if (f == idx)
            return -1;

         // parse relative path
        int l = f!=-1? f-idx: path.Length-idx;
        string comp = path.Substring(idx, l);
        idx += l;

         // look for [n] and [@attr_name="attr_value"] expressions in path components
        int idxBracket = comp.IndexOf('[');
        l = idxBracket!=-1? idxBracket: comp.Length;
        _childName = comp.Substring(0, l);

        if (idxBracket != -1) {
            string expr = XMLHelper.unescape(comp.Substring(idxBracket), '[', ']');
            int i = 0;

            while(i<expr.Length && char.IsWhiteSpace(expr[i])) ++i;

            if (i<expr.Length && char.IsDigit(expr[i])) {
                int n;

                if (Int32.TryParse(expr.Substring(i), out n))    // read index number
                    if (n != 0)
                        _childIdx = n - 1;  // convert into zero based index
            } else {
                while(i<expr.Length && expr[i]=='@') {
                    int idxEqual = expr.IndexOf('=', ++i);

                    if (idxEqual != -1) {
                         // look for delimiters
                        //TODO If there is neither an opening nor a closing delimiter, we should look for white space as delimiter.
                        int idxDel1 = idxEqual + 1;
                        char del1 = expr[idxDel1];
                        int idxDel2 = del1=='\'' || del1=='"'? expr.IndexOf(del1, idxDel1+1): -1;

                         // read attribute name and value
                        string attrName = XMLHelper.unescape(expr.Substring(i, idxEqual-i));
                        string attrValue = idxDel2!=-1? XMLHelper.unescape(expr.Substring(idxDel1, ++idxDel2-idxDel1)):
                                                        XMLHelper.unescape(expr.Substring(idxDel1));

                        _mAttrAndAttr.Add(attrName, attrValue);

                        if (idxDel2 == -1)
                            break;

                        i = idxDel2 + 1;
                        while(i<expr.Length && char.IsWhiteSpace(expr[i])) ++i;

                         // handle [@attr1="value1" and @attr2="value2"] expressions
                         // handle expressions like [@name="1.2" and @profil="IPE" and @date="2006_07"]
                        if (string.Compare(expr, 0, "and ", 0, 4, true) == 0)
                            i += 4;
                    }

                    while(i<expr.Length && char.IsWhiteSpace(expr[i])) ++i;
                }
            }
        }

        return idx;
    }

Here is the call graph for this function:


Member Data Documentation

Definition at line 73 of file XPathElement.cs.

Referenced by matches(), parse(), and XPathElement().

Dictionary<string, string> XMLStorage::XPathElement::_mAttrAndAttr = new Dictionary<string, string>()

Definition at line 76 of file XPathElement.cs.

Referenced by XMLStorage::XMLNode::createRelative(), matches(), parse(), and XPathElement().


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