# Extract data from xml file

**URL:** <https://discuss.elastic.co/t/extract-data-from-xml-file/77534>\
**Category:** Logstash\
**Created:** [March 6, 2017, 3:46pm UTC](https://discuss.elastic.co/t/extract-data-from-xml-file/77534 "2017-03-06T15:46:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mohamed](https://avatars.discourse-cdn.com/v4/letter/m/d78d45/32.png) [@Mohamed](https://discuss.elastic.co/u/Mohamed)\
**Post date:** [March 6, 2017, 3:46pm UTC](https://discuss.elastic.co/t/extract-data-from-xml-file/77534/1 "2017-03-06T15:46:28Z")

</div>

Hello,

I want to dynamically extract information from an xml file, something like this:

`<bookmarket> <book> <title>T1</title> </book> <book> <title>T2</title> </book> </bookmarket>`

I've created a filter:

filter {

xml {  
source =\> "message"  
target =\> "source"  
store\_xml =\> false  
remove\_namespaces =\> true  
xpath =\> [  
#here I don't know the number of books in the xml file  
"count(bookstore/step)","number\_of\_books"  
#I want to create something like this:  
for counter in [1.. %{number\_of\_books}] {  
"bookmarket/book[counter]/title/text()", "bookTitle[counter]"  
}  
]  
force\_array =\> false  
}  
}

Thank you for your help.

---

<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:** [March 7, 2017, 8:38am UTC](https://discuss.elastic.co/t/extract-data-from-xml-file/77534/2 "2017-03-07T08:38:42Z")

</div>

This seems more like an XPath question that's probably better asked where XPath experts hang out.

---

<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:** [April 4, 2017, 8:38am UTC](https://discuss.elastic.co/t/extract-data-from-xml-file/77534/3 "2017-04-04T08:38:42Z")

</div>

Closed on April 4, 2017, 8:38am UTC

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