I’m trying to get a count on my web activity in ADF and to put this on my skip variable.
I got this error:
The function 'xpath' parameters are invalid: the 'xpath' parameter must be a supported, well formed XPath expression.
Image error
The result of my Response :
{
"Response": "<?xml version="1.0" encoding="utf-8"?>
<feed xml:base="https://myXXXXX.sapbydesign.com/sap/byd/odata/ana_businessanalytics_analytics.svc/%5C" xmlns="http://www.w3.org/2005/Atom%5C" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata%5C" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices%5C"><id>https://myXXXXX.sapbydesign.com/sap/byd/odata/ana_businessanalytics_analytics.svc/IDRESULT\</id><title type="text">IDRESULT</title>
<updated>2024-09-12T09:00:04Z</updated>
<author><name/></author><link href="IDREPORT" rel="self" title="IDRESULT"/>
**<m:count>71051</m:count>**
<entry><id>https://myXXXXX.sapbydesign.com/sap/byd/odata/ana_businessanalytics_analytics.svc/form')</id><title type="text">form')</title><updated>2024-09-12T09:00:04Z</updated><category term="sapbyd.IDRESULT" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme%5C"/><link href="FIELD')" rel="self" title="IDRESULT"/><content type="application/xml"><m:properties><value>TEST</value></m:properties></content></entry></feed>",
"ADFWebActivityResponseHeaders": {
"dataserviceversion": "2.0",
"strict-transport-security": "max-age=31536000; includeSubDomains",
"sap-passport-component": "none",
"Cache-Control": "no-cache",
"Set-Cookie": "sap-usercontext=sap-client=231; path=/;HttpOnly;Secure",
"Content-Length": "4614",
"Content-Type": "application/atom+xml; type=feed; charset=utf-8"
},
"effectiveIntegrationRuntime": "AutoResolveIntegrationRuntime (France Central)",
"executionDuration": 160,
"durationInQueue": {
"integrationRuntimeQueue": 0
},`your text`
"billingReference": {`your text`
"activityType": "ExternalActivity",
"billableDuration": [
{
"meterType": "AzureIR",
"duration": 0.049999999999999996,
"unit": "Hours"
}
]
}
}
Have you an idea ?
I trying something like this to set my variable:
@xpath(xml(activity('Web1').output.Response),string('//m:count/text()'))
1
Your xml string contains backslash also you need to go from root so, use below expression.
@xpath(xml(replace(variables('response'), '', '')),string('/*[name()="feed"]/*[name()="m:count"]/text()'))
Here, i am replacing all backslash to empty ''
, then selecting feed
and inside it m:count
.
Using your string as input variable below is the output.
Output:
2
I concur with Michael Kay that your problem will be the m:
namespace prefix used in your XPath.
It’s important to understand that a namespace prefix (such as this m:
) is just an arbitrary alias for a namespace URI (in this case, the URI is http://schemas.microsoft.com/ado/2007/08/dataservices/metadata%5C
). In your XML, the prefix m:
is associated with that URI by the namespace declaration xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata%5C
attached to the root element of the XML. In an XPath query you can use the same prefix used in the XML you are querying (e.g. m:
in this case), or you can use an entirely different prefix, e.g. metadata:
, as long as the prefix was associated with the same namespace URI. The prefix itself is not significant; what is significant is only the URI associated with the prefix.
How you associate a prefix with a namespace URI depends on the host language and the API with which you are invoking your XPath. I had a quick look at the Azure Data Factory documentation and I couldn’t see any way in their API to associate a namespace prefix with a namespace URI in an XPath query. Maybe there is a way, but I couldn’t find it.
However, it is possible to formulate an XPath query to select an element whose name belongs to a namespace, without using a prefix. It’s much less concise, but it will work. You can use the two XPath functions local-name()
and namespace-uri()
to return the “local” name of an element (i.e. the part of the name after the prefix), and the namespace URI of the element (i.e. the URI associated with that prefix).
The following expression matches any child text node of any element (*
) whose local name is count
, and whose namespace URI is http://schemas.microsoft.com/ado/2007/08/dataservices/metadata%5C
//*
[local-name(.)='count']
[namespace-uri(.)='http://schemas.microsoft.com/ado/2007/08/dataservices/metadata%5C']
/text()
But rather than return a text node, I suggest you probably just want to convert the element to a string, and return a string value:
string(
//*
[local-name(.)='count']
[namespace-uri(.)='http://schemas.microsoft.com/ado/2007/08/dataservices/metadata%5C']
)
See https://learn.microsoft.com/en-us/azure/data-factory/control-flow-expression-language-functions#xpath for some examples of using this technique to avoid using namespace prefixes.