string-join() function throws invalid expression - xpath

XPathError
message: "Invalid expression.
(string-join(/form/Data/MProcess/Process/Id/string(), ','))
I thought the problem was Process Id was not returning string so I tried string() and text() but they did not work. I can't find the solution.
Here is an example process id: aee865d1-7253-489c-8d53-2a0d580639d0

string-join() is an XPath 2.0 function, and many early XPath processors were never upgraded to 2.0. Check what XPath processor you are using and what language level it supports, and upgrade if you can.

Related

error parsing dynamic link query using Microsoft Json Rules engine

Using Microsoft Json Rules engine.
The following rule expressions parse without an issue:
"Names[0].PersonName.FirstName=="Paul""
Names.Any()
but 3. throws the following parse exception
"Names.Any(n=>n.PersonName.FirstName=="Paul")"
Exception while parsing expression Names.Any( n => n.PersonName.FirstName=="Paul") - Unable to cast object of type 'System.Linq.Expressions.InstanceMethodCallExpression1' to type 'System.Linq.Expressions.ParameterExpression'.
Dr. Google is not very helpful on this one.
Any feedback, directions, pointers etc. greatly appreciated.
I was expecting the expression to parse and when evaluated return, true, given 1. above is true.
Dynamic Linq using a operator called "it" to refer to the current instance.a
Changing the expression to the following:
"Names.Any(it.PersonName.FirstName=="Paul")" solved the problem for me.

Xpath Error: Can not convert #STRING to a NodeList

In one of the API solution, incoming request is in XML format, and i need to fetch first child node tag name to make decision to run the logic. I am using xpath to get the tag name, when in am running xpath i am getting error "Can not convert #STRING to a NodeList"
I have tried with local-name and name, but both are giving same error.
my xml is as below
<p:Check xmlns:p="http://amarwayx.com.cu/WCSXMLSchema/creptonium">
<AttributeChnageLocal>
<TaskID>17723</TaskID>
<BatchID>12345</BatchID>
<Expiry>2022-12-06</Expiry>
<TimeStamp>2019-07-20T22:45:48</TimeStamp>
</AttributeChnageLocal>
</p:Check>
and Xpath i used are
local-name(/p:Check/*)
name(/p:Check/*)
local-name(/p:Check/*[1])
name(/p:Check/*[1])
how ever is some online xpath evaluator has evaluated correct name(AttributeChnageLocal), i am not getting where the xpath syntax is wrong.
below is my tool snapshot.
same kind of expression works fine
You have ticked a box labelled "store the string value of the selected node as text", which suggests that the XPath evaluation tool you are using expects your XPath expression to select a node; but it doesn't, it selects a string.
I don't know what this tool you are using is, but unfortunately all its options seem to assume that you are selecting nodes.

Can't select XML attributes with Oxygen XQuery implementation; Oxygen XPath emits result

I learned that every Xpath expression is also a valid Xquery expression. I'm using Oxygen 16.1 with this sample XML:
<actors>
<actor filmcount="4" sex="m" id="15">Anderson, Jeff</actor>
<actor filmcount="9" sex="m" id="38">Bishop, Kevin</actor>
</actors>
My expression is:
//actor/#id
When I evaluate this expression in Oxygen with Xpath 3.0, I get exactly what I expect:
15
38
However, when I evaluate this expression with Xquery 3.0 (also 1.0), I get the message: "Your query returned an empty sequence.
Can anyone provide any insight as to why this is, and how I can write the equivalent Xquery statement to get what the Xpath statement did above?
Other XQuery implementations do support this query
If you want to validate that your query (as corrected per discussion in comments) does in fact work with other XQuery implementations when entered exactly as given in the question, you can run it as follows (tested in BaseX):
declare context item := document { <actors>
<actor filmcount="4" sex="m" id="15">Anderson, Jeff</actor>
<actor filmcount="9" sex="m" id="38">Bishop, Kevin</actor>
</actors> };
//actor/#id
Oxygen XQuery needs some extra help
Oxygen XML doesn't support serializing attributes, and consequently discards them from a result sequence when that sequence would otherwise be provided to the user.
Thus, you can work around this with a query such as the following:
//actor/#id/string(.)
data(//actor/#id)
Below applies to a historical version of the question.
Frankly, I would not expect //actors/#id to return anything against that data with any valid XPath or XQuery engine, ever.
The reason is that there's only one place you're recursing -- one // -- and that's looking for actors. The single / between the actors and the #id means that they need to be directly connected, but that's not the case in the data you give here -- there's an actor element between them.
Thus, you need to fix your query. There are numerous queries you could write that would find the data you wanted in this document -- knowing which one is appropriate would require more information than you've provided:
//actor/#id - Find actor elements anywhere, and take their id attribute values.
//actors/actor/#id - Find actors elements anywhere; look for actor elements directly under them, and take the id attribute of such actor elements.
//actors//#id - Find all id attributes in subtrees of actors elements.
//#id - Find id attributes anywhere in the document.
...etc.

Using XPath functions in libxml

I am trying to evaluate certain XPath expressions with libxml 2.8.0 and am getting error messages with functions. It is not clear to me whether libxml implements the whole or a subset of the XPath specification. Is there any resource clearly identifying what is implemented and how to use it?
In my specific case, one expression I am trying to evaluate is:
/TemporalInformation/RecipeInformation[fn:exists(./ActionToActionRelation[fn:contains(./#actionA,'cook') and fn:exists(./IngredientA[fn:contains(./#classes,'onion')])])]
I am using libxml through the XML::LibXML Perl module, but I have also tried my expression with the xpath1.c example tool available from xmlsoft.org, and got the same error messages:
$ ./xpath-tester data/fk.xml "/TemporalInformation/RecipeInformation[fn:exists(.> /ActionToActionRelation[fn:contains(./#actionA,'cook') and fn:exists(./IngredientA[fn:contains(./#classes,'onion')])])]" "fn=http://www.w3.org/2005/xpath-functions"
xmlXPathCompOpEval: function contains not found
XPath error : Unregistered function
xmlXPathCompOpEval: function exists not found
XPath error : Unregistered function
XPath error : Invalid expression
XPath error : Stack usage errror
Error: unable to evaluate xpath expression "/TemporalInformation/RecipeInformation[fn:exists(./ActionToActionRelation[fn:contains(./#actionA,'cook') and fn:exists(./IngredientA[fn:contains(./#classes,'onion')])])]"
Usage: ./xpath-tester <xml-file> <xpath-expr> [<known-ns-list>]
where <known-ns-list> is a list of known namespaces
in "<prefix1>=<href1> <prefix2>=href2> ..." format
I have tried with and without the fn namespace, both with xpath.c and my Perl script, and got the same result.
The libxml XPath implementation is only XPath 1.0, so 2.0-only functions such as exists aren't available. In 1.0 you only have a few core functions - there's starts-with but not ends-with, no regular expression support, no date handling, etc. and there's no strong typing and none of the higher-level constructs like if and for.
So to answer your question, yes, it does support the whole of XPath, but only XPath 1.0.

XPath tokenize() method not recognized by msxml3.dll

I'm attempting to use the tokenize method in a SelectNodes(" ") call, to filter some things out.
I have something along the lines of:
<nodes>
<node colors="RED,BLUE,YELLOW"/>
</nodes>
And my xpath is as such:
nodes/node[not(empty(tokenize("GREEN,YELLOW,PURPLE", ",") intersect tokenize(#colors, ",")))]
Simply, I've got two comma delimited list, one as an attribute, and one as a "filter" for the attributes. I want to select all nodes where #colors contains, somewhere, one of the words inside of "GREEN,YELLOW,PURPLE".
I thought I had the solution for it with that XPath, but it seems either:
A: I did something wrong, or
B: The version of XML DOM document I am using does not support tokenize()
The XPath above, in a SelectNodes( ) call will throw up an error message, saying msxml3.dll: Unknown method.", then pointing to the tokenize() method.
I tried doing setProperty("SelectionLanguage", "XPath"), but that did not seem to solve the issue either.
Is there any way for me to perform an equivalent XPath selection, without resorting to a bunch of and contains(#colors, "GREEN") and contains(#colors, "YELLOW")...?
As JLRishe says, msxml does not support XPath 2.0.
Depending on the environment that you are in there is probably third-party software you can use that supports either XPath 2.0 or XQuery 1.0 (which is a superset of XPath 2.0).
Microsoft's XML software is getting very dated and there has been little new development for 10 years now. It's time to consider alternatives.

Resources