> ## 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.

# xmlOpen

> 从 URI 或静态文本为 XML 数据创建可读句柄，以供后续运算器使用。

从 URI 或静态文本为 XML 数据创建可读句柄。当需要读取静态 XML 数据、来自公共 URI 的 XML 数据，或来自另一个运算器输出的 XML 数据时，此运算器很有用。

## 必需的参数

* 无

## 可选的参数

* **uri**: XML 文件 URI（例如 `http://mydomain.com/resources/somedata.xml` 或 `/tmp/myfile.xml`）。
* **text**: XML 文本。它可以是在 ArcScript 属性上设置的静态 XML，也可以是脚本中先前运算器的输出（例如某个 http 运算器的 `[http:content]` 输出属性）。请参阅下面的示例。

## 输出属性

* **handle**: XML 数据的可读句柄引用。后续运算器可以使用此句柄（请参阅下面的示例）。

## 示例

```xml theme={null}
<!-- Setting a static XML text -->
<arc:set attr="xml.text" value='<Items><foo>bar</foo></Items>' />
<arc:call op="xmlOpen" in="xml" out="output" >
  <!-- Setting the xml handle as an attribute on a new item that is passed into a second operation  -->
  <arc:set attr="xml2.handle" value="[output.handle]" />
  <arc:set attr="xml2.map:value1" value="/Items/foo" />
  <arc:call op="xmlDOMGet" in="xml2" out="output2" >
    <!-- Here is where you can execute additional script for the operation that is using the handle -->
    <!-- This example logs the value of the foo element from the xml text to the application log, which is "bar" -->
    <arc:set attr="_log.info" value="[output2.value1]" />
  </arc:call>
  <arc:finally>
    <!-- Close the xml handle -->
    <arc:call op="xmlClose" in="xml2" />
  </arc:finally>
</arc:call>
```

<Note>使用 xmlOpen 时，请确保在脚本末尾使用对应的 [xmlClose](./op-xml-close) 运算器关闭句柄，以避免通过打开的句柄造成内存泄漏。</Note>
