# Parsing XML in /data with Hugo's new XML support: attributes?

**URL:** <https://discourse.gohugo.io/t/parsing-xml-in-data-with-hugos-new-xml-support-attributes/36654>\
**Category:** support\
**Created:** [January 19, 2022, 4:16pm UTC](https://discourse.gohugo.io/t/parsing-xml-in-data-with-hugos-new-xml-support-attributes/36654 "2022-01-19T16:16:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![wgroeneveld](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/wgroeneveld/32/3315_2.png) [@wgroeneveld](https://discourse.gohugo.io/u/wgroeneveld)\
**Post date:** [January 19, 2022, 4:16pm UTC](https://discourse.gohugo.io/t/parsing-xml-in-data-with-hugos-new-xml-support-attributes/36654/1 "2022-01-19T16:16:59Z")

</div>

Recently, Hugo received XML data support  
See [Implement XML data support · gohugoio/hugo@0eaaa8f · GitHub](https://github.com/gohugoio/hugo/commit/0eaaa8fee37068bfc8ecfb760f770ecc9a7af22a)

I’m trying to get it to work. I have a `.xml` file in my `/data` folder and want to iterate over tags. That works. For instance, getting the contents of `<title>blah</title>` indeed is simple: `{{ $.Site.Data.myfile.head.title }}`.

But what about attributes? Printing the raw value using `{{ . }}` to peek inside the Go vars gives me something akin to `map[-text:Blogging -title:Blogging outline:...` for an XML structure like` <outline text="Blogging" title="Blogging"><.../>`. I want to extract the title and text, and clearly, `{{ .text }}` does not work: that fetches the contents of the text child, which isn’t there.

The documentation on this shiny new feature I’m afraid is far from complete. No mention anywhere of attributes at [transform.Unmarshal | Hugo](https://gohugo.io/functions/transform.unmarshal/).

Thanks!

---

<div class="post-metadata">

**Author:** ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)\
**Post date:** [January 19, 2022, 4:27pm UTC](https://discourse.gohugo.io/t/parsing-xml-in-data-with-hugos-new-xml-support-attributes/36654/2 "2022-01-19T16:27:20Z")

</div>

There’s an open docs issue that might be helpful:  
[https://github.com/gohugoio/hugoDocs/issues/1622](https://github.com/gohugoio/hugoDocs/issues/1622)

> [@wgroeneveld](#):
>
> The documentation on this shiny new feature I’m afraid is far from complete.

Maybe you can help.

---

<div class="post-metadata">

**Author:** ![wgroeneveld](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/wgroeneveld/32/3315_2.png) [@wgroeneveld](https://discourse.gohugo.io/u/wgroeneveld)\
**Post date:** [January 19, 2022, 5:43pm UTC](https://discourse.gohugo.io/t/parsing-xml-in-data-with-hugos-new-xml-support-attributes/36654/3 "2022-01-19T17:43:01Z")

</div>

That was exactly what I was looking for, the `index` fn! Thanks so much!  
It is indeed a bit strange that attributes start with `-`.

I’d love to help with the docs, and I’ve done so before. I’ll add the index information to the page above in a pull request.

Edit: [https://github.com/gohugoio/hugoDocs/issues/1622 an attempt to clear … by wgroeneveld · Pull Request #1637 · gohugoio/hugoDocs · GitHub](https://github.com/gohugoio/hugoDocs/pull/1637)

---

<div class="post-metadata">

**Author:** ![eatyourveg](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/eatyourveg/32/24536_2.png) [@eatyourveg](https://discourse.gohugo.io/u/eatyourveg)\
**Post date:** [May 9, 2025, 7:07pm UTC](https://discourse.gohugo.io/t/parsing-xml-in-data-with-hugos-new-xml-support-attributes/36654/4 "2025-05-09T19:07:46Z")

</div>

filter by attribute  
attribute “id” has hypen added in front  
{{if eq (index $range “-id”) “John”}}  
// code  
{{end}}
