# Split xml like string

**URL:** <https://discuss.elastic.co/t/split-xml-like-string/152217>\
**Category:** Logstash\
**Created:** [October 12, 2018, 10:31am UTC](https://discuss.elastic.co/t/split-xml-like-string/152217 "2018-10-12T10:31:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mortenb123](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mortenb123/32/37227_2.png) [@mortenb123](https://discuss.elastic.co/u/mortenb123)\
**Post date:** [October 12, 2018, 10:31am UTC](https://discuss.elastic.co/t/split-xml-like-string/152217/1 "2018-10-12T10:31:29Z")

</div>

Hi

How can I easily parse the following xml like string into kv strings:

`"controllerstring" => "<dev>SC-M</dev><fw>SC-1 6.1.0-1 Jun 19 2018</fw><pid>48DA97EA-000229</pid><pname></pname><pdate>1222285290</pdate><mac>00:90:c2:d9:1e:c5</mac><clock>1223642611</clock><dst>60</dst><val>1</val><opt>3</opt><ip>192.168.1.103</ip>"`

if([task] and [task] == "WebRaw") {  
grok {  
match =\> { "message" =\> "(?.+)$" }  
tag\_on\_failure =\> []  
}  
if("" in [controllerstring]) {  
xml {  
source =\> "controllerstring"  
target =\> "parsed"  
store\_xml =\> "false"  
}  
}  
}

```
{
                "task" => "WebRaw",
           "indexpart" => "2018-10-10",
            "loglevel" => "Debug",
            "@version" => "1",
                 "mac" => "00:90:c2:d9:1e:c5",
          "@timestamp" => 2018-10-10T10:43:13.000Z,
                "host" => "MB-PC",
          "proxy-uuid" => "e8c1a9b8-0dbb-4aef-90ca-aebff3baea72",
             "message" => "(Web, Raw) 77.16.213.106 << [] <dev>SC-M</dev><fw>SC-1 6.1.0-1 Jun 19 2018</fw><pid>48DA97EA-000229</pid><pname></pname><pdate>1222285290</pdate><mac>00:90:c2:d9:1e:c5</mac><clock>1223642611</clock><dst>60</dst><val>1</val><opt>3</opt><ip>192.168.1.103</ip>",
    "controllerstring" => "<dev>SC-M</dev><fw>SC-1 6.1.0-1 Jun 19 2018</fw><pid>48DA97EA-000229</pid><pname></pname><pdate>1222285290</pdate><mac>00:90:c2:d9:1e:c5</mac><clock>1223642611</clock><dst>60</dst><val>1</val><opt>3</opt><ip>192.168.1.103</ip>",
                "type" => "sensioproxy",
            "sequence" => 0
}
```

---

<div class="post-metadata">

**Author:** ![mortenb123](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mortenb123/32/37227_2.png) [@mortenb123](https://discuss.elastic.co/u/mortenb123)\
**Post date:** [October 15, 2018, 7:10am UTC](https://discuss.elastic.co/t/split-xml-like-string/152217/2 "2018-10-15T07:10:19Z")

</div>

Currently I do the following, buit this does not account for new values:

> if([task] and [task] == "WebRaw") {  
> grok {  
> match =\> { "message" =\> "(?.+)$" }  
> tag\_on\_failure =\>   
> }  
> if("" in [controllerstring]) {  
> grok {  
> match =\> { "controllerstring" =\> "\<dev\>(?.+)\</dev\>" }  
> tag\_on\_failure =\>   
> }  
> grok {  
> match =\> { "controllerstring" =\> "\<fw\>(?.+)\</fw\>" }  
> tag\_on\_failure =\>   
> }  
> grok {  
> match =\> { "controllerstring" =\> "\<ip\>(?.+)\</ip\>" }  
> tag\_on\_failure =\>   
> }  
> grok {  
> match =\> { "controllerstring" =\> "\<cd\>(?.+)\</cd\>" }  
> tag\_on\_failure =\>   
> }  
> grok {  
> match =\> { "controllerstring" =\> "\<hw\>(?.+)\</hw\>" }  
> tag\_on\_failure =\>   
> }  
> grok {  
> match =\> { "controllerstring" =\> "\<serial\>(?.+)\</serial\>" }  
> tag\_on\_failure =\>   
> }  
> mutate {  
> remove\_field =\> "controllerstring"  
> }

---

<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:** [November 12, 2018, 7:23am UTC](https://discuss.elastic.co/t/split-xml-like-string/152217/3 "2018-11-12T07:23:54Z")

</div>

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