# Get Tag Value

This is a pre-built Action located under the **@Generic** Element. The functionality of this Action in Avo Assure is to fetch the tag value based on the input provided and store the result in a dynamic variable.

## **Syntax**

**Input Value**: `<XML block/XML tags>;<number>;<block name>;<tag name>;@<Attribute name(optional)>`&#x20;

| Argument                                   | Description                                                                                                                                                                  |
| ------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <p>\<XML block/XML tags><br>(Required)</p> | Provide the XML block or XML tags from which the tag value needs to be retrieved.                                                                                            |
| <p>\<number><br>(Required)</p>             | Provide the position number of the XML block or tag if multiple matching blocks or tags are available. For example, 1 for the first occurrence, 2 for the second occurrence. |
| <p>\<block name><br>(Required)</p>         | Provide the name of the XML block that contains the required tag.                                                                                                            |
| <p>\<tag name><br>(Required)</p>           | Provide the name of the tag whose value you want to retrieve.                                                                                                                |
| <p>@\<Attribute name><br>(Optional)</p>    | Provide the attribute name if you want to retrieve an attribute value from a particular tag.                                                                                 |

**Output Value**: `<Dynamic Variable>;<Dynamic Variable>(Optional)`&#x20;

| Argument                      | Description                                                                  |
| ----------------------------- | ---------------------------------------------------------------------------- |
| \<Dynamic Variable>(Required) | This dynamic variable stores the fetched key value from XML body or XML Tag. |
| \<Dynamic Variable>(Optional) | This dynamic variable stores the status as **True**, **False** or **None**.  |

### **Example 1: Retrieving a Tag Value using XML Response**

In this example, we explain how to retrieve a specific tag value from an XML response body.

* **Action**: Get Tag Value
* **Input Value**: \<xml\_block>;1,1;library.book;title
  * The first argument (**\<xml\_block>**) specifies the XML block that contains the response data.
  * The second argument (**1,1**) specifies   bthe occurrence number of the block to search.
  * The third argument (**library.book**) specifies the XML block path where the required tag exists.
  * The fourth argument (**title**) specifies the tag name whose value is retrieved.

{% hint style="info" %}
**Note**: you can also provide the whole xml body as first argument.
{% endhint %}

{% code expandable="true" %}

```xml
XMl Body
<library>
    <book id="101">
        <title>Automation Testing Guide</title>
        <author>John Smith</author>
    </book>
    <book id="102">
        <title>API Testing Basics</title>
        <author>David Lee</author>
    </book>
</library>
```

{% endcode %}

* **Output Value**: {title};{Status}
  * The first output variable (**{title}**) stores the retrieved tag value as **Automation Testing Guide**.
    * In this example, the value stored is **Automation Testing Guide**.
  * The second output variable (**{Status}**) stores the execution result with the following possible values:
    * **True**: If the tag value is retrieved successfully.
    * **False**: If the tag or block does not exist in the XML response.
* **Logical Explanation**: The **Get Tag Value** action takes the value from the **Input Value** column (**\<xml\_block>;1,1;library.book;title**) and searches for the **title** tag inside the **library.book** block. The action retrieves the value from the first occurrence of the matching block (**Automation Testing Guide**) and stores it in the **{title}** variable. The execution result is stored in the **{Status}** variable as **True**.

{% hint style="info" %}
**Note**: Use the [Display Variable Value](/avo-assure/actions/generic/variable-operations/display-variable-value.md) action to display the value on the screen.
{% endhint %}

<figure><img src="/files/HRkkZA4iHR0S71Nsrnzd" alt=""><figcaption></figcaption></figure>

<details>

<summary><strong>Traversal Explanation (Aligned with Current Example)</strong></summary>

Traversal is performed from the parent XML block to the child tag using indexes.

To traverse and retrieve the value of the title tag from the XML structure, perform the following actions:

1. Start at Root \<library>
   1. XML begins with the root block \<library>.
2. Navigate to Parent Block (book)
   1. Move inside the **\<library>** block.
   2. **book** acts as the parent block.
   3. It contains multiple **\<book>** elements.
3. Traverse Using Indexes
   1. Use index 1,1 to define the traversal path:
      1. First 1: Select the \<book> block under \<library>.
      2. Second 1: Select the first \<book> element.
4. Reach Child Tag
   1. Inside the selected \<book> block, locate the title tag.
   2. Value present: Automation Testing Guide

#### Traversal Path

* **Index Path**: 1 > 1
* **Block Path**: library.book

Traversal is completed from: Parent Block (book) > Child Tag (title)

#### Execution Flow

1. Start from root block `<library>`.
2. Navigate to parent block book.
3. Select the 1st `<book>` element using index **1,1**.
4. Extract the value of the title tag.

{% hint style="info" %}
**Note**:&#x20;

* Traversal is performed from parent block to child tag:
  * Use:
    * Block name: Used to define block path.
    * Indexes: Used to define traversal path.
  * Use 1 for:
    * First block occurrence.
    * Single available block or tag.
      {% endhint %}

</details>

### **Example 2: Retrieving an Attribute Value from an XML Input**

In this example, we explain how to retrieve a specific attribute value from an XML input body.

* **Action**: Get Tag Value
* **Input Value**: \<xml\_block>;1,1;Order.Customer;Address;@City
  * The first argument (**\<xml\_block>**) specifies the XML block that contains the response data.
  * The second argument (**1,1**) specifies the occurrence number of the block to search.
  * The third argument (**Order.Customer**) specifies the XML block path where the required tag exists.
  * The fourth argument (**Address**) specifies the tag name from which the value is retrieved.
  * The fifth argument (**@City**) specifies the attribute name to retrieve from the selected tag.

{% code overflow="wrap" expandable="true" %}

```xml
XMl Body
<Order>
    <OrderID>1001</OrderID>
    <Customer>
        <Address 
            Type="Billing" 
            City="Mumbai" 
            Country="India" 
            PostalCode="400001" />
    </Customer>
</Order>
```

{% endcode %}

* **Output Value**: {City};{Status}
  * The first output variable (**{City}**) stores the retrieved attribute value as **Mumbai**.
  * The second output variable (**{Status}**) stores the execution result with the following possible values:
    * **True**: If the attribute value is retrieved successfully.
    * **False**: If the tag, block, or attribute does not exist in the XML response.
* **Logical Explanation**: The **Get Tag Value** action takes the value from the **Input Value** column (**\<xml\_block>;1,1;Order.Customer;Address;@City**) and searches for the **City** attribute in the **Message** tag under the **Order.Customer** block. The action retrieves the attribute value (**Mumbai**) from the first matching occurrence and stores it in the **{City}** variable. The execution result is stored in the **{Status}** variable as **True**.

<figure><img src="/files/Rt49ndc503q1uCsV6HSo" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.avoautomation.com/avo-assure/actions/generic/xml-and-json-operations/get-tag-value.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
