# XPATH expression to parse a nested xml file

**URL:** <https://discuss.elastic.co/t/xpath-expression-to-parse-a-nested-xml-file/38941>\
**Category:** Logstash\
**Created:** [January 12, 2016, 6:35am UTC](https://discuss.elastic.co/t/xpath-expression-to-parse-a-nested-xml-file/38941 "2016-01-12T06:35:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tarun\_Sant](https://avatars.discourse-cdn.com/v4/letter/t/a5b964/32.png) [@Tarun\_Sant](https://discuss.elastic.co/u/Tarun_Sant)\
**Post date:** [January 12, 2016, 6:35am UTC](https://discuss.elastic.co/t/xpath-expression-to-parse-a-nested-xml-file/38941/1 "2016-01-12T06:35:04Z")

</div>

Following is the input xml I want to parse.

```
<robot>
	<suite>
		<some_data_1 attr1="value1">
		<some_data_2 attr2="value2">
	</suite>
	<status val="val1">
	<suite>
		<stat time_start=1449504352 time_end=1449504354>test_1</stat>
	</suite>
</robot>

```

From this input xml I want to get the "time\_start" and "time\_end" from the tag.

I have tried with using XPATH, but I am not able to get the data. I am able to get the data using XPATH, but "time\_start" and "time\_end" is not able to get.

Need some help in this regard.

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [January 12, 2016, 7:01am UTC](https://discuss.elastic.co/t/xpath-expression-to-parse-a-nested-xml-file/38941/2 "2016-01-12T07:01:07Z")

</div>

After fixing the XML syntax problems //robot/suite/stat/@time\_start can be used to select one of the attributes. I didn't try it in Logstash but I'd be surprised if it didn't work there. If you still have problems please provide details.

---

<div class="post-metadata">

**Author:** ![Tarun\_Sant](https://avatars.discourse-cdn.com/v4/letter/t/a5b964/32.png) [@Tarun\_Sant](https://discuss.elastic.co/u/Tarun_Sant)\
**Post date:** [January 13, 2016, 8:04am UTC](https://discuss.elastic.co/t/xpath-expression-to-parse-a-nested-xml-file/38941/3 "2016-01-13T08:04:11Z")

</div>

Thanks a log for your reply.

XML I have provided is a custom one and with that I just wanted to show the structure of the nested xml file.  
I have tried in the following format and I am able to extract data.  
/robot//stat/@time\_start

---

<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:** [July 6, 2017, 5:15am UTC](https://discuss.elastic.co/t/xpath-expression-to-parse-a-nested-xml-file/38941/4 "2017-07-06T05:15:57Z")

</div>

Closed on July 6, 2017, 5:15am UTC


