title: Parsing XML file using Logstash
body: <p>I am trying to parse an XML file in Logstash. I want to use XPath to do the parsing of documents in XML. So when I run my config file the data loads into <code>elasticsearch</code> but It is not in the way I want to load the data. The data loaded in <code>elasticsearch</code> is each line in xml document</p>
  
  <p>Structure of my XML file</p>
  
  <p><a href="https://i.stack.imgur.com/xS9HQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xS9HQ.png" alt="enter image description here"></a></p>
  
  <p>What I want to achieve:</p>
  
  <p>create fields in elasticsearch that stores the follwing</p>
  
  <pre><code>ID =1
  Name = "Finch"
  </code></pre>
  
  <p><strong>My Config file:</strong></p>
  
  <pre><code>input{
      file{
          path =&gt; "C:\Users\186181152\Downloads\stations.xml"
          start_position =&gt; "beginning"
          sincedb_path =&gt; "/dev/null"
          exclude =&gt; "*.gz"
          type =&gt; "xml"
      }
  }
  filter{
      xml{
          source =&gt; "message"
          store_xml =&gt; false
          target =&gt; "stations"
          xpath =&gt; [
              "/stations/station/id/text()", "station_id",
              "/stations/station/name/text()", "station_name"
          ]
      }
  }
  
  output{
      elasticsearch{
          codec =&gt; json
          hosts =&gt; "localhost"
          index =&gt; "xmlns"
      }
      stdout{
          codec =&gt; rubydebug
      }
  }
  </code></pre>
  
  <p>Output in Logstash:</p>
  
  <pre><code>{
      "station_name" =&gt; "%{station_name}",
      "path" =&gt; "C:\Users\186181152\Downloads\stations.xml",
      "@timestamp" =&gt; 2018-02-09T04:03:12.908Z,
      "station_id" =&gt; "%{station_id}",
      "@version" =&gt; "1",
      "host" =&gt; "BW",
      "message" =&gt; "\t\r",
      "type" =&gt; "xml"
  }
  </code></pre>