# How to extract field name which has space in them using xpath

**URL:** <https://discuss.elastic.co/t/how-to-extract-field-name-which-has-space-in-them-using-xpath/258201>\
**Category:** Logstash\
**Created:** [December 9, 2020, 11:57pm UTC](https://discuss.elastic.co/t/how-to-extract-field-name-which-has-space-in-them-using-xpath/258201 "2020-12-09T23:57:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kamalbeg](https://avatars.discourse-cdn.com/v4/letter/k/aca169/32.png) [@kamalbeg](https://discuss.elastic.co/u/kamalbeg)\
**Post date:** [December 9, 2020, 11:57pm UTC](https://discuss.elastic.co/t/how-to-extract-field-name-which-has-space-in-them-using-xpath/258201/1 "2020-12-09T23:57:30Z")

</div>

I have following xml code

```auto
xml {
       source => "message"
        store_xml => "false"
      remove_namespaces => "true"
      xpath => [
          '/E2ETraceEvent/System/Computer/text()', "[grc][System][Computer]",
          '/E2ETraceEvent/System/Correlation/text()', "[grc][System][Correlation]",
          '/E2ETraceEvent/System/`Source Name`/text()', "[grc][System][Source]"
        ]
   }
  
But it fails when I have space in my xml field name

<E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent">
    <System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system">
        <EventID>0</EventID>
        <Type>3</Type>
        <SubType Name="Error">0</SubType>
        <Level>2</Level>
        <TimeCreated SystemTime="2020-10-21T04:47:38.0146329Z" />
        <Source Name="Archer.Web" />
        <Correlation ActivityID="{00000000-0000-0000-0000-000000000000}" />
        <Execution ProcessName="w3wp" ProcessID="6884" ThreadID="226" />
        <Assembly Version>6.7.300.1039</AssemblyVersion>
        <Channel />
        <Computer>ABCXYZ</Computer>
    </System>
</E2ETraceEvent>

How do I extract fields with space in them such as
SubType Name
TimeCreated SystemTime
xpath extracts Compter just fine.
```

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [December 10, 2020, 12:53am UTC](https://discuss.elastic.co/t/how-to-extract-field-name-which-has-space-in-them-using-xpath/258201/2 "2020-12-10T00:53:51Z")

</div>

> [@kamalbeg](#):
>
> `it fails when I have space in my xml field name`

That is not what you have. XML element names cannot contain spaces. You have a Source element that has a Name attribute.

```auto
<Assembly Version>6.7.300.1039</AssemblyVersion>

```

Note that you have an extra space in `Assembly Version` that causes the xml filter to silently fail. If you fix that then you can use

```
    xml {
        source => "message"
        store_xml => false
        remove_namespaces => true
        xpath => {
            "/E2ETraceEvent/System/Computer/text()" => "[grc][System][Computer]"
            "/E2ETraceEvent/System/Correlation/text()" => "[grc][System][Correlation]"
            "/E2ETraceEvent/System/Source/@Name" => "[grc][System][Source]"
        }
    }

```

to get yourself

```
       "grc" => {
    "System" => {
          "Source" => [
            [0] "Archer.Web"
        ],
        "Computer" => [
            [0] "ABCXYZ"
        ]
    }
},

```

---

<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:** [January 7, 2021, 12:53am UTC](https://discuss.elastic.co/t/how-to-extract-field-name-which-has-space-in-them-using-xpath/258201/3 "2021-01-07T00:53:58Z")

</div>

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