Пример #1
0
        } //Build

        internal IQuery Build(string query, bool allowVar, bool allowKey)
        {
            this.allowVar     = allowVar;
            this.allowKey     = allowKey;
            this.allowCurrent = true;
            return(Build(XPathParser.ParseXPathExpresion(query), query));
        }
Пример #2
0
        bool ToXpath1(string xpath2, out string xpath1)
        {
            var builder = new XPath2Rewriter();
            xpath1 = new XPathParser<string>().Parse(xpath2, builder);

            return builder.RewriteRequired;
        }
Пример #3
0
 internal IQuery BuildPatternQuery(string query, bool allowVar, bool allowKey)
 {
     this.allowVar     = allowVar;
     this.allowKey     = allowKey;
     this.allowCurrent = false;
     return(Build(XPathParser.ParseXPathPattern(query), query));
 }
Пример #4
0
        internal static XPathExpression Compile(string xpath, IXmlNamespaceResolver nsmgr, IStaticXsltContext ctx)
        {
            XPathParser        xpathParser        = new XPathParser(ctx);
            CompiledExpression compiledExpression = new CompiledExpression(xpath, xpathParser.Compile(xpath));

            compiledExpression.SetContext(nsmgr);
            return(compiledExpression);
        }
Пример #5
0
		internal static XPathExpression Compile (string xpath,
			NSResolver nsResolver, IStaticXsltContext ctx)
		{
			XPathParser parser = new XPathParser (ctx);
			CompiledExpression x = new CompiledExpression (xpath, parser.Compile (xpath));
			x.SetContext (nsResolver);
			return x;
		}
Пример #6
0
        internal static XPathExpression Compile(string xpath,
                                                NSResolver nsResolver, IStaticXsltContext ctx)
        {
            XPathParser        parser = new XPathParser(ctx);
            CompiledExpression x      = new CompiledExpression(xpath, parser.Compile(xpath));

            x.SetContext(nsResolver);
            return(x);
        }
Пример #7
0
		public static AstNode ParseXPathPattern(string xpathPattern) {
			XPathScanner scanner = new XPathScanner(xpathPattern);
			XPathParser  parser  = new XPathParser(scanner);
            AstNode result = parser.ParsePattern(null);
            if (scanner.Kind != XPathScanner.LexKind.Eof) {
                throw new XPathException(Res.Xp_InvalidToken, scanner.SourceText);
            }
			return result;
		}
Пример #8
0
        public void Unions()
        {
            var xpath2 = "exists(@a | @b)";
            var builder = new XPath2Rewriter();
            var xpath1 = new XPathParser<string>().Parse(xpath2, builder);

            Console.WriteLine(xpath2);
            Console.WriteLine(xpath1);
            Assert.IsFalse(builder.RewriteRequired);
        }
Пример #9
0
        public void NumericCompare()
        {
            var xpath2 = "foo[count(@a) > 0]";
            var builder = new XPath2Rewriter();
            var xpath1 = new XPathParser<string>().Parse(xpath2, builder);

            Console.WriteLine(xpath2);
            Console.WriteLine(xpath1);
            Assert.IsFalse(builder.RewriteRequired);
        }
Пример #10
0
 static internal AstNode NewAstNode(String parsestring)
 {
     try {
         return(XPathParser.ParseXPathExpresion(parsestring));
     }
     catch (XPathException e)
     {
         Debug.WriteLine(e.Message);
     }
     return(null);
 }
Пример #11
0
        public static AstNode ParseXPathPattern(string xpathPattern)
        {
            XPathScanner scanner = new XPathScanner(xpathPattern);
            XPathParser  parser  = new XPathParser(scanner);
            AstNode      result  = parser.ParsePattern(null);

            if (scanner.Kind != XPathScanner.LexKind.Eof)
            {
                throw new XPathException(Res.Xp_InvalidToken, scanner.SourceText);
            }
            return(result);
        }
Пример #12
0
        public void ParsingErrors()
        {
            var big = "not(starts-with(f:reference/@value, '#')) or exists(ancestor::a:content/f:*/f:contained/f:*[@id=substring-after(current()/f:reference/@value, '#')]|/f:*/f:contained/f:*[@id=substring-after(current()/f:reference/@value, '#')])";
            var p1 = "not(starts-with(f:reference/@value, '#'))";
            var p2 = "ancestor::a:content/f:*/f:contained/f:*[@id=substring-after(current()/f:reference/@value, '#')]";
            var p3 = "/f:*/f:contained/f:*[@id=substring-after(current()/f:reference/@value, '#')]";
            var p4 = "/f:*[@id='#']";
            var p5 = "/f:foo[@id='#']";

            var xpath2 = p4;
            var builder = new XPath2Rewriter();
            var xpath1 = new XPathParser<string>().Parse(xpath2, builder);

            Console.WriteLine(xpath2);
            Console.WriteLine(xpath1);
        }
	public virtual XPathExpression Compile(String xpath)
			{
				XPathParser parser = new XPathParser();
				return parser.Parse(xpath);
			}
Пример #14
0
        // don't return true or false, if it's invalid path, just throw exception during the process
        // for whitespace thing, i will directly trim the tree built here...
        public void CompileXPath(string xPath, bool isField, XmlNamespaceManager nsmgr)
        {
            if ((xPath == null) || (xPath == string.Empty))
            {
                throw new XmlSchemaException(Res.Sch_EmptyXPath);
            }

            // firstly i still need to have an ArrayList to store tree only...
            // can't new ForwardAxis right away
            string[]  xpath    = xPath.Split('|');
            ArrayList AstArray = new ArrayList(xpath.Length);

            this.fAxisArray = new ArrayList(xpath.Length);

            // throw compile exceptions
            // can i only new one builder here then run compile several times??
            try {
                foreach (string value in xpath)
                {
                    // default ! isdesorself (no .//)
                    Axis ast = (Axis)(XPathParser.ParseXPathExpresion(value));
                    AstArray.Add(ast);
                }
            }
            catch {
                throw  new XmlSchemaException(Res.Sch_ICXpathError, xPath);
            }

            Axis stepAst;

            foreach (Axis ast in AstArray)
            {
                // Restricted form
                // field can have an attribute:

                // throw exceptions during casting
                if ((stepAst = ast) == null)
                {
                    throw new XmlSchemaException(Res.Sch_ICXpathError, xPath);
                }

                Axis top = stepAst;

                // attribute will have namespace too
                // field can have top attribute
                if (IsAttribute(stepAst))
                {
                    if (!isField)
                    {
                        throw new XmlSchemaException(Res.Sch_SelectorAttr, xPath);
                    }
                    else
                    {
                        SetURN(stepAst, nsmgr);
                        try {
                            stepAst = (Axis)(stepAst.Input);
                        }
                        catch {
                            throw new XmlSchemaException(Res.Sch_ICXpathError, xPath);
                        }
                    }
                }

                // field or selector
                while ((stepAst != null) && (IsNameTest(stepAst) || IsSelf(stepAst)))
                {
                    // trim tree "." node, if it's not the top one
                    if (IsSelf(stepAst) && (ast != stepAst))
                    {
                        top.Input = stepAst.Input;
                    }
                    else
                    {
                        top = stepAst;
                        // set the URN
                        if (IsNameTest(stepAst))
                        {
                            SetURN(stepAst, nsmgr);
                        }
                    }
                    try {
                        stepAst = (Axis)(stepAst.Input);
                    }
                    catch {
                        throw new XmlSchemaException(Res.Sch_ICXpathError, xPath);
                    }
                }

                // the rest part can only be .// or null
                // trim the rest part, but need compile the rest part first
                top.Input = null;
                if (stepAst == null)        // top "." and has other element beneath, trim this "." node too
                {
                    if (IsSelf(ast) && (ast.Input != null))
                    {
                        this.fAxisArray.Add(new ForwardAxis(DoubleLinkAxis.ConvertTree((Axis)(ast.Input)), false));
                    }
                    else
                    {
                        this.fAxisArray.Add(new ForwardAxis(DoubleLinkAxis.ConvertTree(ast), false));
                    }
                    continue;
                }
                if (!IsDescendantOrSelf(stepAst))
                {
                    throw new XmlSchemaException(Res.Sch_ICXpathError, xPath);
                }
                try {
                    stepAst = (Axis)(stepAst.Input);
                }
                catch {
                    throw new XmlSchemaException(Res.Sch_ICXpathError, xPath);
                }
                if ((stepAst == null) || (!IsSelf(stepAst)) || (stepAst.Input != null))
                {
                    throw new XmlSchemaException(Res.Sch_ICXpathError, xPath);
                }

                // trim top "." if it's not the only node
                if (IsSelf(ast) && (ast.Input != null))
                {
                    this.fAxisArray.Add(new ForwardAxis(DoubleLinkAxis.ConvertTree((Axis)(ast.Input)), true));
                }
                else
                {
                    this.fAxisArray.Add(new ForwardAxis(DoubleLinkAxis.ConvertTree(ast), true));
                }
            }
        }
Пример #15
0
 static void RunTestTree(string xpathExpr)
 {
     Console.WriteLine("Original XPath: {0}", xpathExpr);
     try {
         XElement xe = new XPathParser<XElement>().Parse(xpathExpr, new XPathTreeBuilder());
         XmlWriterSettings ws = new XmlWriterSettings(); {
             ws.Indent = true;
             ws.OmitXmlDeclaration = true;
         }
         using (XmlWriter w = XmlWriter.Create(Console.Out, ws)) {
             xe.WriteTo(w);
         }
     } catch (XPathParserException e) {
         Console.WriteLine(e.ToString());
     }
     Console.WriteLine();
     Console.WriteLine();
 }
Пример #16
0
        public virtual XPathExpression Compile(String xpath)
        {
            XPathParser parser = new XPathParser();

            return(parser.Parse(xpath));
        }