You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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

  1. First, retrieve all attribute nodes with your existing XPath expression:
    xpath(xml(outputs('Compose')), '//request/@id')
    
    This returns an array of attribute nodes (each formatted like "id="31998"").
  2. 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()), '="'), '"')
      
    This works by:
    • 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:

  1. Parse the XML into an object using:
    xml(outputs('Compose'))
    
  2. Access the array of request nodes (adjust the path to match your XML root):
    For example, if your XML starts with <requests>...</requests>, use:
    outputs('Parse_XML')?['requests']?['request']
    
  3. Add a Select action to extract the @id property from each request object:
    • In "From", select the request array from the previous step.
    • In "Map", use:
      item()?['@id']
      
    This directly gives you the pure numeric ID values as strings (convert to numbers with 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.01 17:05:11