public void UnsupportedComparand_RightToLeft() { var p = XPathCompiler.Compile("a[$b=$c]"); Assert.That(p.Path, Is.Not.Null); Assert.That(p.Path.Expression, Is.EqualTo("a[$b=$c]")); Assert.That(p.IsCreatable, Is.False); Assert.That(p.Depth, Is.EqualTo(0)); Assert.That(p.FirstStep, Is.Null); }
public void MultipleComparisonsWithSelf() { var p = XPathCompiler.Compile("a[.='1'][.='2']"); Assert.That(p.Path, Is.Not.Null); Assert.That(p.Path.Expression, Is.EqualTo("a[.='1'][.='2']")); Assert.That(p.IsCreatable, Is.False); Assert.That(p.Depth, Is.EqualTo(0)); Assert.That(p.FirstStep, Is.Null); }
public void UnsupportedOperator_LeftToRight() { var p = XPathCompiler.Compile("a[b or c]"); Assert.That(p.Path, Is.Not.Null); Assert.That(p.Path.Expression, Is.EqualTo("a[b or c]")); Assert.That(p.IsCreatable, Is.False); Assert.That(p.Depth, Is.EqualTo(0)); Assert.That(p.FirstStep, Is.Null); }
public void AttributeParent_InPredicate() { var p = XPathCompiler.Compile("a[@b/c]"); Assert.That(p.Path, Is.Not.Null); Assert.That(p.Path.Expression, Is.EqualTo("a[@b/c]")); Assert.That(p.IsCreatable, Is.False); Assert.That(p.Depth, Is.EqualTo(0)); Assert.That(p.FirstStep, Is.Null); }
public void UnsupportedQualifiedName() { var p = XPathCompiler.Compile("a:*"); Assert.That(p.Path, Is.Not.Null); Assert.That(p.Path.Expression, Is.EqualTo("a:*")); Assert.That(p.IsCreatable, Is.False); Assert.That(p.Depth, Is.EqualTo(0)); Assert.That(p.FirstStep, Is.Null); }
public void UnsupportedTrailingOperators() { var p = XPathCompiler.Compile("f()"); Assert.That(p.Path, Is.Not.Null); Assert.That(p.Path.Expression, Is.EqualTo("f()")); Assert.That(p.IsCreatable, Is.False); Assert.That(p.Depth, Is.EqualTo(0)); Assert.That(p.FirstStep, Is.Null); }
public void UnsupportedLocalName() { var p = XPathCompiler.Compile("*"); Assert.NotNull(p.Path); Assert.AreEqual("*", p.Path.Expression); Assert.False(p.IsCreatable); Assert.AreEqual(0, p.Depth); Assert.IsNull(p.FirstStep); }
public void UnsupportedLocalName_Attribute() { var p = XPathCompiler.Compile("@*"); Assert.That(p.Path, Is.Not.Null); Assert.That(p.Path.Expression, Is.EqualTo("@*")); Assert.That(p.IsCreatable, Is.False); Assert.That(p.Depth, Is.EqualTo(0)); Assert.That(p.FirstStep, Is.Null); }
public void UnsupportedLocalName_PredicateChild() { var p = XPathCompiler.Compile("a[b/*]"); Assert.That(p.Path, Is.Not.Null); Assert.That(p.Path.Expression, Is.EqualTo("a[b/*]")); Assert.That(p.IsCreatable, Is.False); Assert.That(p.Depth, Is.EqualTo(0)); Assert.That(p.FirstStep, Is.Null); }
public void MultipleComparisonsWithSelf() { var p = XPathCompiler.Compile("a[.='1'][.='2']"); Assert.NotNull(p.Path); Assert.AreEqual("a[.='1'][.='2']", p.Path.Expression); Assert.False(p.IsCreatable); Assert.AreEqual(0, p.Depth); Assert.IsNull(p.FirstStep); }
public void UnsupportedTrailingOperators() { var p = XPathCompiler.Compile("f()"); Assert.NotNull(p.Path); Assert.AreEqual("f()", p.Path.Expression); Assert.False(p.IsCreatable); Assert.AreEqual(0, p.Depth); Assert.IsNull(p.FirstStep); }
public void UnsupportedComparand_RightToLeft() { var p = XPathCompiler.Compile("a[$b=$c]"); Assert.NotNull(p.Path); Assert.AreEqual("a[$b=$c]", p.Path.Expression); Assert.False(p.IsCreatable); Assert.AreEqual(0, p.Depth); Assert.IsNull(p.FirstStep); }
public void UnsupportedOperator_LeftToRight() { var p = XPathCompiler.Compile("a[b or c]"); Assert.NotNull(p.Path); Assert.AreEqual("a[b or c]", p.Path.Expression); Assert.False(p.IsCreatable); Assert.AreEqual(0, p.Depth); Assert.IsNull(p.FirstStep); }
public void AttributeParent_InPredicate() { var p = XPathCompiler.Compile("a[@b/c]"); Assert.NotNull(p.Path); Assert.AreEqual("a[@b/c]", p.Path.Expression); Assert.False(p.IsCreatable); Assert.AreEqual(0, p.Depth); Assert.IsNull(p.FirstStep); }
public void Select() { var node = NodeForElement("<X> <A/> </X>"); var path = XPathCompiler.Compile("A"); var cursor = node.Select(path, IncludedTypes, NamespaceSource.Instance, CursorFlags.Elements); Assert.That(cursor, Is.Not.Null); Assert.That(cursor.MoveNext(), Is.True); Assert.That(cursor.Name.LocalName, Is.EqualTo("A")); Assert.That(cursor.MoveNext(), Is.False); }
public void Select() { var node = NodeForElement("<X> <A/> </X>"); var path = XPathCompiler.Compile("A"); var cursor = node.Select(path, IncludedTypes, NamespaceSource.Instance, CursorFlags.Elements); Assert.NotNull(cursor); Assert.True(cursor.MoveNext()); Assert.AreEqual("A", cursor.Name.LocalName); Assert.False(cursor.MoveNext()); }
private bool AssertType(XdmNode assertion, SingleResultDoc result, XPathCompiler assertXpc) { if (IsException()) { return(false); } else { XPathSelector s = assertXpc.Compile("$result instance of " + assertion.StringValue).Load(); s.SetVariable(new QName("result"), result.value); return(((XdmAtomicValue)s.EvaluateSingle()).GetBooleanValue()); } }
private bool assertDeepEq(XdmNode assertion, SingleResultDoc result, XPathCompiler assertXpc) { if (IsException()) { return(false); } else { XPathSelector s = assertXpc.Compile("deep-equal($result , (" + assertion.StringValue + "))").Load(); s.SetVariable(new QName("result"), result.value); return(((XdmAtomicValue)s.Evaluate()).GetBooleanValue()); } }
private bool assertEq(XdmNode assertion, SingleResultDoc result, XPathCompiler assertXpc) { if (IsException()) { return(false); } else { XPathSelector s = assertXpc.Compile("$result eq " + assertion.StringValue).Load(); s.SetVariable(new QName("result"), result.value); XdmAtomicValue item = (XdmAtomicValue)s.EvaluateSingle(); return(item != null && item.GetBooleanValue()); } }
private bool assertPermutation(XdmNode assertion, SingleResultDoc result, XPathCompiler assertXpc) { // TODO: extend this to handle nodes (if required) if (IsException()) { return(false); } else { return(true); try { int expectedItems = 0; HashSet <string> expected = new HashSet <string>(); XPathSelector s = assertXpc.Compile("(" + assertion.StringValue + ")").Load(); s.SetVariable(new QName("result"), result.value); // not used, but we declared it JCodepointCollator collator = JCodepointCollator.getInstance(); //JXPathContext context = new JXPathContextMajor(stringValue.EMPTY_string, assertXpc.getUnderlyingStaticContext().getConfiguration()); foreach (XdmItem item in s) { expectedItems++; XdmValue value = (XdmValue)item.Simplify; // value.Simplify. /* Object comparable = value.isNaN() ? * AtomicSortComparer.COLLATION_KEY_NaN : * value.getXPathComparable(false, collator, context); * expected.Add(comparable);*/ } int actualItems = 0; foreach (XdmItem item in GetPrincipalResult()) { actualItems++; XdmValue value = (XdmValue)item.Simplify; /*Object comparable = value.isNaN() ? * AtomicSortComparer.COLLATION_KEY_NaN : * value.getXPathComparable(false, collator, context); */ // if (!expected.Contains(comparable)) { return(false); // } } return(actualItems == expectedItems); } catch (DynamicError) { return(false); } } }
public void NestedPredicates() { var p = XPathCompiler.Compile("aa[bb[cc]]"); Assert.NotNull(p.Path); Assert.AreEqual("aa[bb[cc]]", p.Path.Expression); Assert.True(p.IsCreatable); Assert.AreEqual(1, p.Depth); var s = p.FirstStep; Assert.NotNull(s); Assert.NotNull(s.Path); Assert.AreEqual("aa[bb[cc]]", s.Path.Expression); Assert.IsNull(s.Prefix); Assert.AreEqual("aa", s.LocalName); Assert.False(s.IsAttribute); Assert.IsNull(s.Value); Assert.IsNull(s.NextStep); Assert.AreSame(s.NextStep, s.NextNode); Assert.IsNull(s.PreviousNode); Assert.NotNull(s.Dependencies); Assert.AreEqual(1, s.Dependencies.Count); var n = s.Dependencies[0]; Assert.NotNull(n); Assert.IsNull(n.Prefix); Assert.AreEqual("bb", n.LocalName); Assert.False(n.IsAttribute); Assert.IsNull(n.Value); Assert.IsNull(n.NextNode); Assert.IsNull(n.PreviousNode); Assert.NotNull(s.Dependencies); Assert.AreEqual(1, s.Dependencies.Count); n = n.Dependencies[0]; Assert.NotNull(n); Assert.IsNull(n.Prefix); Assert.AreEqual("cc", n.LocalName); Assert.False(n.IsAttribute); Assert.IsNull(n.Value); Assert.IsNull(n.NextNode); Assert.IsNull(n.PreviousNode); Assert.NotNull(n.Dependencies); CollectionAssert.IsEmpty(n.Dependencies); }
public void NestedPredicates() { var p = XPathCompiler.Compile("aa[bb[cc]]"); Assert.That(p.Path, Is.Not.Null); Assert.That(p.Path.Expression, Is.EqualTo("aa[bb[cc]]")); Assert.That(p.IsCreatable, Is.True); Assert.That(p.Depth, Is.EqualTo(1)); var s = p.FirstStep; Assert.That(s, Is.Not.Null); Assert.That(s.Path, Is.Not.Null); Assert.That(s.Path.Expression, Is.EqualTo("aa[bb[cc]]")); Assert.That(s.Prefix, Is.Null); Assert.That(s.LocalName, Is.EqualTo("aa")); Assert.That(s.IsAttribute, Is.False); Assert.That(s.Value, Is.Null); Assert.That(s.NextStep, Is.Null); Assert.That(s.NextNode, Is.SameAs(s.NextStep)); Assert.That(s.PreviousNode, Is.Null); Assert.That(s.Dependencies, Is.Not.Null & Has.Count.EqualTo(1)); var n = s.Dependencies[0]; Assert.That(n, Is.Not.Null); Assert.That(n.Prefix, Is.Null); Assert.That(n.LocalName, Is.EqualTo("bb")); Assert.That(n.IsAttribute, Is.False); Assert.That(n.Value, Is.Null); Assert.That(n.NextNode, Is.Null); Assert.That(n.PreviousNode, Is.Null); Assert.That(s.Dependencies, Is.Not.Null & Has.Count.EqualTo(1)); n = n.Dependencies[0]; Assert.That(n, Is.Not.Null); Assert.That(n.Prefix, Is.Null); Assert.That(n.LocalName, Is.EqualTo("cc")); Assert.That(n.IsAttribute, Is.False); Assert.That(n.Value, Is.Null); Assert.That(n.NextNode, Is.Null); Assert.That(n.PreviousNode, Is.Null); Assert.That(n.Dependencies, Is.Not.Null & Is.Empty); }
protected string GetValue(string xpath, XmlNode parent, XmlNamespaceManager nsManager, bool isNarrative) { try { if (!xpath.StartsWith("/") && parent is XmlElement) { xpath = "/*/" + xpath; } var parentXdmNode = builder.Build(parent); var compiledXpath = compiler.Compile(xpath); var selector = compiledXpath.Load(); selector.ContextItem = parentXdmNode; var results = selector.Evaluate().GetList(); if (results.Count == 1) { return(results[0].GetStringValue()); } else if (results.Count > 1) { String ret = ""; foreach (var next in results) { if (!string.IsNullOrEmpty(ret)) { ret += ", "; } ret += next.GetStringValue(); } return(ret); } return(null); } catch (Exception ex) { LogEvent?.Invoke("XPATH/Configuration error \"" + xpath + "\": " + ex.Message + "\r\n"); } return(null); }
public XmlNode SelectNode(string location) { XPathSelector xpSel; try { xpSel = _compile.Compile(location).Load(); xpSel.ContextItem = _dom; foreach (XdmNode xdmn in xpSel) { return(xdmn.getUnderlyingXmlNode()); } } catch (Exception ex) { throw ex; } return(null); }
public string Process(string xml, string xpath) { var executable = _compiler.Compile(xpath); var evaluator = executable.Load(); //set default context node: var doc = new XmlDocument(); doc.LoadXml(xml); var root = _builder.Build(doc.DocumentElement); evaluator.ContextItem = root; var value = evaluator.Evaluate(); var result = String.Join(Environment.NewLine, value.Cast <XdmItem>() .Select(o => o.ToString()) ); return(result); }
public void QualifiedAttributeName() { var p = XPathCompiler.Compile("@pp:aa"); Assert.That(p.Path, Is.Not.Null); Assert.That(p.Path.Expression, Is.EqualTo("@pp:aa")); Assert.That(p.IsCreatable, Is.True); Assert.That(p.Depth, Is.EqualTo(1)); var s = p.FirstStep; Assert.That(s, Is.Not.Null); Assert.That(s.Path, Is.Not.Null); Assert.That(s.Path.Expression, Is.EqualTo("@pp:aa")); Assert.That(s.Prefix, Is.EqualTo("pp")); Assert.That(s.LocalName, Is.EqualTo("aa")); Assert.That(s.IsAttribute, Is.True); Assert.That(s.Value, Is.Null); Assert.That(s.NextStep, Is.Null); Assert.That(s.NextNode, Is.SameAs(s.NextStep)); Assert.That(s.PreviousNode, Is.Null); Assert.That(s.Dependencies, Is.Not.Null & Is.Empty); }
public void MultipleStepsWithSelfReference() { var p = XPathCompiler.Compile("aa/./bb"); Assert.NotNull(p.Path); Assert.AreEqual("aa/./bb", p.Path.Expression); Assert.True(p.IsCreatable); Assert.AreEqual(2, p.Depth); var s = p.FirstStep; Assert.NotNull(s); Assert.NotNull(s.Path); Assert.AreEqual("aa", s.Path.Expression); Assert.IsNull(s.Prefix); Assert.AreEqual("aa", s.LocalName); Assert.False(s.IsAttribute); Assert.IsNull(s.Value); Assert.AreSame(s.NextStep, s.NextNode); Assert.IsNull(s.PreviousNode); Assert.NotNull(s.Dependencies); CollectionAssert.IsEmpty(s.Dependencies); s = s.NextStep; Assert.NotNull(s); Assert.NotNull(s.Path); Assert.AreEqual("bb", s.Path.Expression); Assert.IsNull(s.Prefix); Assert.AreEqual("bb", s.LocalName); Assert.False(s.IsAttribute); Assert.IsNull(s.Value); Assert.IsNull(s.NextStep); Assert.AreSame(s.NextStep, s.NextNode); Assert.AreSame(p.FirstStep, s.PreviousNode); Assert.NotNull(s.Dependencies); CollectionAssert.IsEmpty(s.Dependencies); }
public void QualifiedAttributeName() { var p = XPathCompiler.Compile("@pp:aa"); Assert.NotNull(p.Path); Assert.AreEqual("@pp:aa", p.Path.Expression); Assert.True(p.IsCreatable); Assert.AreEqual(1, p.Depth); var s = p.FirstStep; Assert.NotNull(s); Assert.NotNull(s.Path); Assert.AreEqual("@pp:aa", s.Path.Expression); Assert.AreEqual("pp", s.Prefix); Assert.AreEqual("aa", s.LocalName); Assert.True(s.IsAttribute); Assert.IsNull(s.Value); Assert.IsNull(s.NextStep); Assert.AreSame(s.NextStep, s.NextNode); Assert.IsNull(s.PreviousNode); Assert.NotNull(s.Dependencies); CollectionAssert.IsEmpty(s.Dependencies); }
protected string runXSLT(String testName, String xml, String xsl, QName initialMode, QName initialTemplate, String outfile, Hashtable paramTable, String initialContextPath, bool useAssociated, bool schemaAware, String validationMode, bool recoverRecoverable) { Serializer sr = new Serializer(); sr.SetOutputFile(outfile); Processor f; //if (noCacheTests.contains(testName) || testName.startsWith("schemaas20") || // testName.startsWith("striptype20") || testName.startsWith("notation20")) { // create a custom Processor to avoid schema caching //} else { if (schemaAware) { f = schemaAwareProcessor; } else if (xml11) { f = processor; // Use an Xml 1.1 processor } else { f = processor; } //} XdmNode source = null; IList errors = new ArrayList(); XsltCompiler compiler = f.NewXsltCompiler(); compiler.ErrorList = errors; XsltExecutable sheet = null; XsltTransformer inst; if (useAssociated) { try { source = buildSource(f.NewDocumentBuilder(), xml, validationMode); } catch (Exception e) { Console.WriteLine("Failed to build source document: " + e.Message); return("ErrorBBB"); } try { sheet = compiler.CompileAssociatedStylesheet(source); } catch (Exception e) { Console.WriteLine("Failed to compile stylesheet: " + e.Message); if (errors.Count > 0) { QName code = ((StaticError)errors[0]).ErrorCode; return(code == null ? "ErrorXXX" : code.LocalName); } else { return("ErrorXXX"); } } } else { Stream stream = new FileStream(xsl, FileMode.Open, FileAccess.Read); compiler.BaseUri = new Uri(xsl); try { sheet = compiler.Compile(stream); } catch (Exception e) { if (errors.Count > 0) { return(((StaticError)errors[0]).ErrorCode.LocalName); } else { Console.WriteLine(e.Message); return("ErrorXXX"); } } finally { stream.Close(); } } if (source == null && xml != null) { try { source = buildSource(f.NewDocumentBuilder(), xml, validationMode); } catch (Exception e) { Console.WriteLine("Failed to build source document: " + e.Message); return("ErrorCCC"); } } if (initialContextPath != null) { XPathCompiler xc = f.NewXPathCompiler(); XPathExecutable exp = xc.Compile(initialContextPath); XPathSelector xpe = exp.Load(); xpe.ContextItem = source; XdmNode node = (XdmNode)xpe.EvaluateSingle(); source = node; } inst = sheet.Load(); if (initialMode != null) { inst.InitialMode = initialMode; } if (initialTemplate != null) { try { inst.InitialTemplate = initialTemplate; } catch (DynamicError e) { QName code = e.ErrorCode; if (code != null) { return(code.LocalName); } else { return("ErrYYYYY"); } } } if (paramTable != null) { foreach (DictionaryEntry de in paramTable) { inst.SetParameter((QName)de.Key, new XdmAtomicValue(de.Value.ToString())); } } inst.InitialContextNode = source; //inst.setURIResolver(factory.getURIResolver()); //inst.setErrorListener(errorListener); //((Controller)inst).setRecoveryPolicy(recoverRecoverable ? Configuration.RECOVER_SILENTLY : Configuration.DO_NOT_RECOVER); // To avoid test results being dependent on the date and time (and timezone), set a fixed // date and time for the run //((Controller)inst).setCurrentDateTime(new DateTimeValue("2005-01-01T12:49:30.5+01:00")); try { inst.Run(sr); } catch (DynamicError e) { Console.WriteLine(e.Message); QName code = e.ErrorCode; if (code != null) { return(code.LocalName); } else { return("ErrYYYYY"); } } return(null); // indicating success }
public void Node_IsSimple_NoNextNodeOrDependency() { var p = XPathCompiler.Compile("a"); Assert.True(p.FirstStep.IsSimple); }