Shape XML into Go structs with xml.Name scaffolding, optional JSON tags, and omitempty flags you control. Nothing uploads. The preview is a starting point for hand-tuned types.
The hard part of XML in Go is not typing struct keywords. The hard part is knowing which nodes repeat, which attributes matter, and when a string is really a decimal or a timestamp. This page gives you a fast sketch from a sample document so you are not staring at a blank file.
We walk the first document you paste, group repeated child tags into slices, and attach xml (and optional json) tags so encoding/xml has something concrete to bind. Numbers are guessed from text shape, not from XSD rules. Attributes become separate fields with ,attr in the xml tag when xml tags stay enabled.
Your XML loads through DOMParser. If the browser reports a parse error, we stop and show the left banner so you fix entities or closing tags first. When the tree is valid, we start at the root element, read direct child elements and attributes, and build nested struct types for distinct element names.
Each generated type carries XMLName xml.Name with a root tag string so unmarshaling has an anchor. We also emit a stub UnmarshalXML method you extend or delete. The stub is honest about being a placeholder: many teams prefer standard Unmarshal with struct tags alone.
JSON-first services still receive XML at edges: bank files, government feeds, older ERP exports. When you already normalized JSON for the rest of the stack, compare the same payload through our XML to JSON converter to see field names side by side before you commit to Go struct names.
Regex stays tempting for one-off extractions. The win here is structural: you get nested types instead of a flat map of strings, which matters once you call xml.Unmarshal for real. Regex still wins for log scraping or when you only need one XPath-like value and refuse to model the whole tree.
| Approach | Strength | Weak spot |
|---|---|---|
| This generator | Fast struct skeleton from a sample | No XSD or RELAX NG awareness |
| Official codegen from schema | Exact models when schema is trustworthy | Heavier setup, schema must exist |
| Manual structs | Full control over tags and pointers | Slow for wide documents |
CDATA blocks collapse to text. Comments disappear. Processing instructions are ignored. Order of sibling elements with different names is preserved only indirectly through separate fields, not through a capture-everything slice. If you need ordered mixed lists, generate once, then refactor into custom types.
Omitempty adds ,omitempty to tags you toggle on. Empty semantics still follow Go rules: zero values skip during marshal when omitempty is present, which surprises newcomers for structs and pointers.
Sometimes the task is exploration, not compilation. Pretty-print the same file with the XML pretty print tool, test expressions in the XPath tester, or diff variants with the XML diff utility before you lock struct names.
Treat the first output as a sketch, not a merge request.
UnmarshalXML method based on whether you need custom start-element handling.xml.Marshal and compare against the source document for surprises.Teams working near SOAP stacks often keep a golden-file test: one trimmed response checked into the repo, unmarshaled in CI, compared field by field. The generator shortens day-one typing. Tests keep day-fifty honest.
Last reviewed: March 2026. Generator output is a draft. Run gofmt, adjust pointer versus value fields, and add tests against real payloads.