XML to Go Converter Online — Generate Struct

Paste any XML and generate encoding/xml-ready Go structs. Attributes map to xml:"name,attr" tags, child elements to xml:"name", and nested structures get their own structs — all in your browser.

What is an XML to Go converter?

An XML to Go converter takes a real XML document and emits Go struct definitions with encoding/xml struct tags ready for xml.Unmarshal. The OpenFormatter generator inspects every element and attribute, infers Go types, and produces a complete struct hierarchy with `xml:"name"`, `xml:"name,attr"`, and `xml:",chardata"` tags — saving the tedious step of writing them by hand for SOAP, RSS, or sitemap XML.

XML differs from JSON in two ways your Go model has to honour. First, XML has attributes on elements (<book id="bk101">) — these need the ,attr tag modifier so encoding/xml reads them from the attribute table, not as child elements. Second, XML has namespaces; the basic generator strips them, but you can re-add them as xml:"namespace-uri name". Both aspects are handled by the sample below.

Sample XML and the Go struct it generates

Input XML

<book id="bk101" lang="en">
  <title>The Go Programming Language</title>
  <year>2015</year>
  <price currency="USD">39.99</price>
</book>

Generated Go

type Book struct {
    XMLName xml.Name `xml:"book"`
    Id      string   `xml:"id,attr"`
    Lang    string   `xml:"lang,attr"`
    Title   string   `xml:"title"`
    Year    int      `xml:"year"`
    Price   Price    `xml:"price"`
}

Notice Id and Lang use ,attr, while Title and Year have no modifier. The nested <price currency="USD">39.99</price> generates a Price struct with one ,attr field and one ,chardata field for the text content — exactly what encoding/xml expects.

How to convert XML to Go — 4 steps

  1. Paste your XML. A SOAP envelope body, an RSS feed entry, a sitemap.xml — anything well-formed.
  2. Click Convert. The browser parses the XML and generates encoding/xml-tagged Go structs for the full element tree.
  3. Review attribute mapping. Confirm that ,attr appears on the fields you want as XML attributes; tweak field names if needed.
  4. Drop into your project. Copy the output into a .go file, then unmarshal real XML with xml.Unmarshal(data, &root).

encoding/xml Tags

Generates xml:"name", xml:"name,attr", and xml:",chardata" struct tags so the resulting structs work with the standard library xml.Unmarshal and xml.Marshal.

Attribute vs Element

XML attributes get the ,attr modifier in their struct tag; child elements do not. The distinction is preserved exactly so round-tripping is lossless.

Client-Side Only

Your XML — including SOAP responses with credentials — is parsed in JavaScript on your machine. Verify in DevTools: zero network requests on Convert.

Common use cases

  • check_circleGenerate Go structs for a SOAP service response
  • check_circleBuild Go models for an RSS or Atom feed reader
  • check_circleParse sitemaps.xml into typed Go structs for crawlers
  • check_circleGenerate Go types from an XSD-described XML file
  • check_circleCreate unmarshalling models for legacy enterprise XML
  • check_circleBuild typed structs for a SAML or WS-Security XML payload
  • check_circleGenerate Go models for AWS XML responses (S3 ListBucket, SQS, SNS)
  • check_circleCreate structs for Maven pom.xml or .NET csproj-style descriptors

Why client-side conversion matters

SOAP responses and enterprise XML often contain customer PII, API tokens, internal endpoint names, and database identifiers. Pasting them into a server-hosted converter is a compliance violation in most regulated industries. OpenFormatter parses the XML and generates Go code entirely in JavaScript on your device — no upload, no logs, no cookies. Open DevTools → Network and confirm no requests fire when you click Convert.

More XML tooling

Validate, format, or convert XML to other languages — every tool runs locally in your browser.

Frequently Asked Questions

How does the output use struct tags for attr vs element?

Element children get `xml:"name"` tags. Attributes get `xml:"name,attr"` — the ,attr modifier tells encoding/xml to read from the attribute table on the parent element instead of looking for a child element of the same name. Element text content uses `xml:",chardata"`. The single tag syntax keeps all metadata on the field declaration where Go developers expect it.

Is the output compatible with encoding/xml?

Yes — encoding/xml is the only XML library targeted. Decode with xml.Unmarshal(data, &root) where root is a *Root pointer; the tagged fields are populated automatically. The same struct round-trips via xml.Marshal so you can produce equivalent XML on output.

How does it handle the root element name?

The top-level struct includes an XMLName xml.Name field tagged with the source root element name. encoding/xml uses this on both Marshal and Unmarshal to bind the correct element. If you rename the struct you do not need to rename the XML — just keep the tag.

How are repeated elements handled?

Repeated child elements like <tag>...</tag> become a slice []TagType on the parent struct. encoding/xml automatically appends each occurrence to the slice. Empty input produces a nil slice; one element produces a slice of length one.

What about XML namespaces?

Namespace-qualified elements use the full xml:"namespace-uri name" tag form. The basic generator strips prefixes; for namespaced unmarshalling rewrite the tag as `xml:"http://example.com/ns localname"` and encoding/xml will match the namespace correctly.

Can elements with attributes and text content be modeled?

Yes. <price currency="USD">39.99</price> generates a struct with two fields — Currency tagged `xml:"currency,attr"` and a Value field tagged `xml:",chardata"`. encoding/xml populates the text body into the chardata field while reading the attribute separately.

Is the XML I paste sent to your servers?

No. XML is parsed by the browser DOMParser and the Go code is generated entirely in JavaScript on your machine. Open DevTools → Network and you will see no requests when you click Convert. Safe for SOAP responses and configuration files containing API keys or credentials.

How do I unmarshal XML into the generated struct?

Use encoding/xml: var book Book; if err := xml.Unmarshal([]byte(data), &book); err != nil { log.Fatal(err) } — the tagged fields are populated automatically. For streaming use xml.NewDecoder(reader).Decode(&book), which is preferable for large documents.

XML to Go Converter Online — Generate Struct | OpenFormatter