# Xpath from array to single fields

**URL:** <https://discuss.elastic.co/t/xpath-from-array-to-single-fields/97572>\
**Category:** Logstash\
**Created:** [August 18, 2017, 11:55am UTC](https://discuss.elastic.co/t/xpath-from-array-to-single-fields/97572 "2017-08-18T11:55:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![EloaCardoso](https://avatars.discourse-cdn.com/v4/letter/e/7cd45c/32.png) [@EloaCardoso](https://discuss.elastic.co/u/EloaCardoso)\
**Post date:** [August 18, 2017, 11:55am UTC](https://discuss.elastic.co/t/xpath-from-array-to-single-fields/97572/1 "2017-08-18T11:55:27Z")

</div>

I have a xml file like this:

```
    <NameValuePair>
    <ParameterName>Name</ParameterName>
    <ParameterValue>Maria</ParameterValue>
    </NameValuePair>
    <NameValuePair>
    <:ParameterName>Age</ParameterName>
    <ParameterValue>23</ParameterValue>
    </NameValuePair>

```

I use xpath in filter like this:  
xpath =\> [  
"//NameValuePair/ParameterName/text()", parametername\_txt,  
"//NameValuePair/ParameterValue/text()", parametervalue\_txt  
]

But I get this in cmd console:  
"parametername\_txt" =\> [  
[0] "Name",  
[1] "Age"  
],  
"parametervalue\_txt" =\> [  
[0] "Maria",  
[1] "23"  
]

The I tried to use also in filter:

```
mutate {
	add_field => {"%{[parametername_txt]}" => "%{[parametervalue_txt]}"}
}

```

And then I got this:  
`"Name,Age" => "Maria,23"`

But I want to get something like this:  
"Name" =\> "Maria",  
"Age" =\> "23"

I know that I can get each element doing this:  
mutate {  
add\_field =\> {"%{[parametername\_txt][0]}" =\> "%{[parametervalue\_txt][0]}"}  
add\_field =\> {"%{[parametername\_txt][1]}" =\> "%{[parametervalue\_txt][1]}"}  
}

But the number of elements is not fixed. I could had have 3, 4, whatever... For example:  
"Name" =\> "Maria",  
"Age" =\> "23",  
"Address" =\> "ABC",  
"Color" =\> "blue"  
...  
How can I do this? I got stuck in this problem :-(☹ Can anyone help me?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [September 15, 2017, 11:55am UTC](https://discuss.elastic.co/t/xpath-from-array-to-single-fields/97572/2 "2017-09-15T11:55:32Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
