> ## Documentation Index
> Fetch the complete documentation index at: https://docs.kasoftware.com/llms.txt
> Use this file to discover all available pages before exploring further.

# xmlDOMSearch

> 使用 xpath 循环输入 XML 文档中的元素，以枚举重复结构。

循环输入 XML 文档中的元素。

## 必需的参数

* **xpath**: 要循环的指定片段的从 1 开始的索引 xpath。例如，`<arc:set attr="myinputitem.xpath" value="/Items/foo/" />`。

## 可选的参数

* **uri**: XML 文件 URI。例如，`http://mydomain.com/resources/somedata.xml`、`/tmp/myfile.xml` 或 `[FilePath]`。
* **text**: XML 数据的可读句柄引用。该句柄由 [xmlOpen](./op-xml-open) 运算器创建，当输入 XML 不是文件或原始文本，或需要执行多个访问文档文件数据的操作时，此句柄很有帮助。
* **handle**: XML 数据的可读句柄引用。该句柄由 xmlOpen 运算器创建，仅当目标 XML 不是输入文件时才需要。有关详细信息和示例，请参阅 [xmlOpen](./op-xml-open)。

## 输出属性

* **xpath**: 返回正在循环的指定元素的完整从 1 开始的索引 xpath。例如，`[myoutitem.xpath]` 会解析为 `foo` XML 元素的 xpath，即 `/Items/foo[1]`。
* **xname**: 返回正在循环的元素的名称。例如，`[myoutitem.xname]` 会解析为 `foo` XML 元素的名称，即 `foo`。

## 示例

请考虑以下作为输入文件传入的 XML：

```xml theme={null}
<Items>
    <hello>world</hello>
    <colors>
        <color>yellow</color>
        <example>banana</example>
    </colors>
    <colors>
        <color>red</color>
        <example>apple</example>
    </colors>
    <colors>
        <color>orange</color>
        <example>orange</example>
    </colors>
</Items>
```

你可以使用 xmlDOMSearch 运算器枚举每个 `colors` 父元素中的所有子元素，如下所示：

```xml theme={null}
<!-- Setting the input uri and xpath -->
<arc:set attr="xml.uri" value="[FilePath]" />
<arc:set attr="xml.xpath" value="/Items/colors" />

<!-- Calling the operation, passing in the xml item --> 
<arc:call op="xmlDOMSearch" in="xml" >
  <!-- Inside the call you can reference elements at paths relative to the input "xpath" -->
  <!-- In this example each color and example is written to the output data -->
  <arc:set attr="_log.info" value="Color = [xpath(color)]" />
  <arc:set attr="_log.info" value="Example = [xpath(example)]" />
</arc:call>

<!-- Setting the output file and pushing the file out -->
<arc:set attr="output.filepath" value="[FilePath]" />
<arc:push item="output" />
```

应用程序日志中的输出如下所示：

<img src="https://mintcdn.com/qiao/bVtjD3fvHFZBo1vE/public/images/jsonDOMSearch.png?fit=max&auto=format&n=bVtjD3fvHFZBo1vE&q=85&s=ad513378142485d723ebd18f73483e98" width="600" data-path="public/images/jsonDOMSearch.png" />
