Beispiel #1
0
        // Parse xpath (limited to above grammar), using provided namespaceResolver
        // to resolve prefixes.
        XPathStep[] ParseXPath(string xpath, IXmlNamespaceResolver xnr)
        {
            int pos;
            int stepCount = 1;

            for (pos = 1; pos < (xpath.Length - 1); pos++)
            {
                if (('/' == xpath[pos]) && ('.' != xpath[pos + 1]))
                {
                    stepCount++;
                }
            }
            XPathStep[] steps = new XPathStep[stepCount];
            pos = 0;
            int i = 0;

            for (;;)
            {
                if (pos >= xpath.Length)
                {
                    throw new XmlException(SR.XmlDataBinding_XPathEnd, (string[])null);
                }
                if ('/' != xpath[pos])
                {
                    throw new XmlException(SR.XmlDataBinding_XPathRequireSlash, (string[])null);
                }
                pos++;
                char ch = xpath[pos];
                if (ch == '.')
                {
                    pos++;
                    // again...
                }
                else if ('@' == ch)
                {
                    if (0 == i)
                    {
                        throw new XmlException(SR.XmlDataBinding_XPathAttrNotFirst, (string[])null);
                    }
                    pos++;
                    if (pos >= xpath.Length)
                    {
                        throw new XmlException(SR.XmlDataBinding_XPathEnd, (string[])null);
                    }
                    steps[i].name = ParseQName(xpath, ref pos, xnr);
                    steps[i].type = XPathNodeType.Attribute;
                    i++;
                    if (pos != xpath.Length)
                    {
                        throw new XmlException(SR.XmlDataBinding_XPathAttrLast, (string[])null);
                    }
                    break;
                }
                else
                {
                    steps[i].name = ParseQName(xpath, ref pos, xnr);
                    steps[i].type = XPathNodeType.Element;
                    i++;
                    if (pos == xpath.Length)
                    {
                        break;
                    }
                }
            }
            Debug.Assert(i == steps.Length);
            return(steps);
        }
 void PopulateFromXPath(XPathNode nd, XPathStep[] steps, int step) {
     string ln = steps[step].name.Name;
     string ns = steps[step].name.Namespace;
     if (XPathNodeType.Attribute == steps[step].type) {
         XPathNode ndAttr = nd.GetAttribute( ln, ns, true);
         if (null != ndAttr) {
             if (null != ndAttr.SchemaAttribute)
                 this.rows.Add(ndAttr);
         }
     }
     else {
         XPathNode ndChild = TreeNavigationHelper.GetElementChild(nd, ln, ns, true);
         if (null != ndChild) {
             int nextStep = step+1;
             do {
                 if (steps.Length == nextStep) {
                     if (null != ndChild.SchemaType)
                         this.rows.Add(ndChild);
                 }
                 else {
                     PopulateFromXPath(ndChild, steps, nextStep);
                 }
                 ndChild = TreeNavigationHelper.GetElementSibling(ndChild, ln, ns, true);
             } while (null != ndChild);
         }
     }
 }
 // Parse xpath (limited to above grammar), using provided namespaceResolver
 // to resolve prefixes.
 XPathStep[] ParseXPath(string xpath, IXmlNamespaceResolver xnr) {
     int pos;
     int stepCount = 1;
     for (pos=1; pos<(xpath.Length-1); pos++) {
         if ( ('/' == xpath[pos]) && ('.' != xpath[pos+1]) )
             stepCount++;
     }
     XPathStep[] steps = new XPathStep[stepCount];
     pos = 0;
     int i = 0;
     for (;;) {
         if (pos >= xpath.Length)
             throw new XmlException(Res.XmlDataBinding_XPathEnd, (string[])null);
         if ('/' != xpath[pos])
             throw new XmlException(Res.XmlDataBinding_XPathRequireSlash, (string[])null);
         pos++;
         char ch = xpath[pos];
         if (ch == '.') {
             pos++;
             // again...
         }
         else if ('@' == ch) {
             if (0 == i)
                 throw new XmlException(Res.XmlDataBinding_XPathAttrNotFirst, (string[])null);
             pos++;
             if (pos >= xpath.Length)
                 throw new XmlException(Res.XmlDataBinding_XPathEnd, (string[])null);
             steps[i].name = ParseQName(xpath, ref pos, xnr);
             steps[i].type = XPathNodeType.Attribute;
             i++;
             if (pos != xpath.Length)
                 throw new XmlException(Res.XmlDataBinding_XPathAttrLast, (string[])null);
             break;
         }
         else {
             steps[i].name = ParseQName(xpath, ref pos, xnr);
             steps[i].type = XPathNodeType.Element;
             i++;
             if (pos == xpath.Length)
                 break;
         }
     }
     Debug.Assert(i == steps.Length);
     return steps;
 }
Beispiel #4
0
        public XPathStep getStep()
        {
            if (nodeTestType == NODE_TEST_TYPE_ABBR_DOT)
            {
                return(XPathStep.ABBR_SELF());
            }
            else if (nodeTestType == NODE_TEST_TYPE_ABBR_DBL_DOT)
            {
                return(XPathStep.ABBR_PARENT());
            }
            else
            {
                XPathStep step;

                if (axisType == AXIS_TYPE_NULL)
                {
                    axisVal = XPathStep.AXIS_CHILD;
                }
                else if (axisType == AXIS_TYPE_ABBR)
                {
                    axisVal = XPathStep.AXIS_ATTRIBUTE;
                }

                if (nodeTestType == NODE_TEST_TYPE_QNAME)
                {
                    step = new XPathStep(axisVal, nodeTestQName);
                }
                else if (nodeTestType == NODE_TEST_TYPE_WILDCARD)
                {
                    step = new XPathStep(axisVal, XPathStep.TEST_NAME_WILDCARD);
                }
                else if (nodeTestType == NODE_TEST_TYPE_NSWILDCARD)
                {
                    step = new XPathStep(axisVal, nodeTestNamespace);
                }
                else
                {
                    String funcName = nodeTestFunc.name.ToString();
                    int    type;
                    if (funcName.Equals("node"))
                    {
                        type = XPathStep.TEST_TYPE_NODE;
                    }
                    else if (funcName.Equals("text"))
                    {
                        type = XPathStep.TEST_TYPE_TEXT;
                    }
                    else if (funcName.Equals("comment"))
                    {
                        type = XPathStep.TEST_TYPE_COMMENT;
                    }
                    else if (funcName.Equals("processing-instruction"))
                    {
                        type = XPathStep.TEST_TYPE_PROCESSING_INSTRUCTION;
                    }
                    else
                    {
                        throw new SystemException();
                    }

                    step = new XPathStep(axisVal, type);
                    if (nodeTestFunc.args.Count > 0)
                    {
                        step.literal = (String)((ASTNodeAbstractExpr)nodeTestFunc.args[0]).getToken(0).val;
                    }
                }

                XPathExpression[] preds = new XPathExpression[predicates.Count];
                for (int i = 0; i < preds.Length; i++)
                {
                    preds[i] = ((ASTNode)predicates[i]).build();
                }
                step.predicates = preds;

                return(step);
            }
        }