Power Automate中XPath提取XML请求ID纯数值的问题求助
Solution to Extract All Numeric IDs from XML in Power Automate
Here are two reliable methods to get all pure numeric IDs from your XML's request nodes:
Method 1: Use XPath + String Manipulation
- First, retrieve all attribute nodes with your existing XPath expression:
This returns an array of attribute nodes (each formatted likexpath(xml(outputs('Compose')), '//request/@id')"id="31998""). - Add a Select action to process this array:
- In the "From" field, select the output from the XPath step.
- In the "Map" field, use this expression to extract the numeric ID:
substringBefore(substringAfter(string(item()), '="'), '"')
- Converting the attribute node to a string (
string(item())) - Grabbing everything after
'="''(substringAfter(...)) - Taking everything before the closing quote (
substringBefore(...))
Method 2: Direct XML Object Access (Simpler)
If your XML has a predictable structure (e.g., a root node containing multiple request nodes), you can skip XPath entirely:
- Parse the XML into an object using:
xml(outputs('Compose')) - Access the array of
requestnodes (adjust the path to match your XML root):
For example, if your XML starts with<requests>...</requests>, use:outputs('Parse_XML')?['requests']?['request'] - Add a Select action to extract the
@idproperty from each request object:- In "From", select the request array from the previous step.
- In "Map", use:
item()?['@id']
int(item()?['@id'])if needed).
Why Your Previous Attempts Failed
string(//request/@id)only returns the first attribute value because XPath 1.0 (used by Power Automate) converts a node-set to string by taking the first node.//request/@id/text()returns null because attributes don't have text nodes—their value is the attribute itself.
内容的提问来源于stack exchange,提问作者Fixermister
相关产品推荐
相关产品推荐

