# Create separate documents from xml file

**URL:** <https://discuss.elastic.co/t/create-separate-documents-from-xml-file/144147>\
**Category:** Logstash\
**Created:** [August 13, 2018, 10:01am UTC](https://discuss.elastic.co/t/create-separate-documents-from-xml-file/144147 "2018-08-13T10:01:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![safaa](https://avatars.discourse-cdn.com/v4/letter/s/65b543/32.png) [@safaa](https://discuss.elastic.co/u/safaa)\
**Post date:** [August 13, 2018, 10:01am UTC](https://discuss.elastic.co/t/create-separate-documents-from-xml-file/144147/1 "2018-08-13T10:01:19Z")

</div>

Hi, I have an xml file , and want to parse it to logstash . is it possible to create a separate documents for each tag ? here is my xml file:

```
<xmldata>
    <head1>
        <key1>Value1</key1>
       <key2> Value2 </key2>
       <id> 00001 </id>
       <date> 01-01-2016 09:00:00 </date>
    </head1>
   <ReportItems>
         <ReportItem>
              <Name>SqlInjection</Name>
        </ReportItem>
        <ReportItem>
            <Name>XSS </Name>
       </ReportItem>
   </ReportItems>
</xmldata>

```

Here is my logstash config file :

```
input {
  file {
       path => "/home/user/test.xml"
       start_position => "beginning"
       sincedb_path => "/dev/null"

       codec => multiline {

               pattern => "^<xmldata>"
               negate => "true"
               what => "previous"
        }
      }
}

filter{

    xml{
      target => "xml_content"
       store_xml => false
       source => "message"
       xpath =>
       [
       "/xmldata/head1/key1/text()", "key1",
       "/xmldata/head1/key2/text()", "key2",
       "/xmldata/ReportItems/ReportItem/Name/text()", "Name"
       ]
      }

      mutate {
         remove_field => ["message"]
      }

     date {
       match => ["date", "dd-MM-yyyy HH:mm:ss"]
       timezone => "Europe/Amsterdam"
          }
}

output{
      elasticsearch {
      hosts => ["localhost:9200"]
      }

}

```

Thanks.

---

<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:** [August 13, 2018, 11:05am UTC](https://discuss.elastic.co/t/create-separate-documents-from-xml-file/144147/2 "2018-08-13T11:05:56Z")

</div>

The split filter can split the elements of an array into one document per item, so if you use the xml filter and possibly others filters to craft such an array the split filter will take care of the rest.

---

<div class="post-metadata">

**Author:** ![safaa](https://avatars.discourse-cdn.com/v4/letter/s/65b543/32.png) [@safaa](https://discuss.elastic.co/u/safaa)\
**Post date:** [August 13, 2018, 11:15am UTC](https://discuss.elastic.co/t/create-separate-documents-from-xml-file/144147/3 "2018-08-13T11:15:36Z")

</div>

Thank you so much, it works 😃

---

<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 10, 2018, 11:15am UTC](https://discuss.elastic.co/t/create-separate-documents-from-xml-file/144147/4 "2018-09-10T11:15:43Z")

</div>

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