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