How to Convert Go to XML - Step by Step Guide
Input Your Go Code
Start by pasting your Go struct literal or slice of structs that you want as XML. Handy for SOAP services and data exchange.
Click Convert
Click the green Convert button to send your Go code to our server, which turns it into XML and sends it back. The XML is shown exactly as received.
Copy or Download XML
Copy the XML to your clipboard or download it as an .xml file for SOAP services, REST APIs, or any XML-based data exchange. Need to check it is well-formed first? Run it through our XML validator.
What is Go to XML Conversion?
Go to XML conversion turns Go data structures like structs, slices, and maps into hierarchical XML. It is useful for SOAP web services, REST APIs, RSS feeds, and exchanging data with systems that speak XML.
Go's own encoding/xml package handles this in code; this tool gives you a quick preview without writing and running Go. You can also convert to other formats with Go to JSON or Go to YAML.
Frequently Asked Questions
What Go format should I use?
A Go struct literal (Type{...}) or a slice of structs ([]Type{...}). Field names become the element names, nested structs become nested elements, and slices become repeated elements.
Is my Go code sent to a server?
Yes. When you click Convert, the code in the editor is sent to our server, which builds the XML and sends it back. Nothing is sent while you type, paste or upload, and nothing is kept — a reload starts with an empty editor. Leave passwords, API keys and other secrets out of the code you convert.
Are long numbers kept exactly?
Yes. The XML comes back as plain text and is shown exactly as received, so long IDs like 8901240544102066246, codes like 00501 and prices like 14.50 are never rounded or reformatted. Want to read the result as a sortable table? Open it in XML to Table.
Can I use the XML in SOAP or REST services?
The result is standard XML with the special characters (<, >, &, quotes) escaped, so it fits SOAP payloads, REST APIs, RSS feeds and other XML-based systems. If you need to be sure it is well-formed, check it with our XML validator.
How does this relate to encoding/xml in Go?
It gives you a quick preview of the XML you could get from your struct, similar to serializing it with the encoding/xml package, without writing and running any Go yourself. The field names you pass in become the element names.
Is it free?
Yes, and there is no sign-up. Every conversion goes through our server, so when a lot of requests arrive at once you may be asked to wait a minute and try again. Going the other way? JSON to XML turns a JSON document into XML.
Related Tools
Go to JSON
Convert Go structs and data structures to JSON format
Go to YAML
Convert Go structs to YAML configuration format
Go to TOML
Convert Go structs to TOML configuration format
Go to CSV
Export Go data to CSV for spreadsheets and data analysis
Go to SQL
Generate SQL CREATE TABLE and INSERT statements from Go structs
Go to Protobuf
Generate Protocol Buffers schema from Go structs for gRPC