# XML Plugin - How to make an attribute filed a key

**URL:** <https://discuss.elastic.co/t/xml-plugin-how-to-make-an-attribute-filed-a-key/132915>\
**Category:** Logstash\
**Created:** [May 23, 2018, 2:38am UTC](https://discuss.elastic.co/t/xml-plugin-how-to-make-an-attribute-filed-a-key/132915 "2018-05-23T02:38:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![iwelch82](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/iwelch82/32/31404_2.png) [@iwelch82](https://discuss.elastic.co/u/iwelch82)\
**Post date:** [May 23, 2018, 2:38am UTC](https://discuss.elastic.co/t/xml-plugin-how-to-make-an-attribute-filed-a-key/132915/1 "2018-05-23T02:38:45Z")

</div>

I have used Beats and Logstash extensively in the past for shipping and analyzing logs with ES and Kibana. For this project I'm looking at taking XML files from our test system, [RobotFramework](http://robotframework.org), and piping them into ES for analysis. I'm not an XML expert so please excuse me if I'm using the wrong nomenclature.

I have the following XML document:

```auto
<?xml version="1.0" encoding="UTF-8"?>
<robot generated="20171114 00:42:17.928" generator="Robot 3.0.2 (Python 2.7.12 on win32)">
<metadata>
  <item name="Board Temperature">32.0</item>
  <item name="Cell1 Ant DBm">-73</item>
  <item name="Cell1 Loss Offset">-9</item>
  <item name="Cell2 Ant DBm">-77</item>
  <item name="Cell2 Loss Offset">-9</item>
</metadata>
</robot>

```

I would like the all of the `item` tags to show up in ES as Key / Values with the Key being the `name` attribute and the value being the tags text. For example

```auto
"record" : {
  "Board Temperature": "32.0",
  "Cell1 Ant DBm": "-73"
}

```

I have the follow Logstash code working but I'm a bit stumped on how to get it structured properly. I would like to avoid the Ruby plugin if possible.

```auto
input {                                                                                                                 
  file {                                                                                                                
    codec => multiline {                                                                                                
      pattern => "<?xml"                                                                                                
      negate => "true"                                                                                                  
      what => "previous"                                                                                                
      auto_flush_interval => 1                                                                                          
    }                                                                                                                   
    path => "/Users/iwelch/Documents/logstash-6.2.4/ft-log-files/test.xml"                                              
    start_position => "beginning"                                                                                       
    sincedb_path => "/dev/null"                                                                                         
  }                                                                                                                     
}                                                                                                                       
                                                                                                                        
                                                                                                                        
filter {                                                                                                                
  xml {                                                                                                                 
    source => "message"                                                                                                 
    store_xml => true                                                                                                   
    target => "record"                                                                                                  
    xpath => ["/robot/metadata/item", "meta"]                                                                           
  }                                                                                                                     
                                                                                                                        
}                                                                                                                       
                                                                                                                        
output {                                                                                                                
  stdout { codec => rubydebug }                                                                                         
}     

```

Cheers!

---

<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:** [June 20, 2018, 2:38am UTC](https://discuss.elastic.co/t/xml-plugin-how-to-make-an-attribute-filed-a-key/132915/2 "2018-06-20T02:38:48Z")

</div>

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