← 返回命令列表

Linux command

zek 命令

文件

复制后可按需替换文件名、目录或参数。

常用示例

Generate Go struct from XML file

zek [file.xml]

Generate struct from XML stdin

cat [file.xml] | zek

Generate with custom struct name

zek -n [StructName] [file.xml]

Use compact output format

zek -c [file.xml]

Read from URL

zek [https://example.com/feed.xml]

说明

zek generates Go struct definitions from XML documents. It analyzes the XML structure and produces type-safe Go code that can unmarshal (and marshal) that XML format. Given an XML file, zek infers the structure and generates appropriate Go types with proper xml struct tags. It handles nested elements, attributes, repeated elements (slices), and mixed content. This is useful for quickly creating Go types for consuming XML APIs, parsing XML data files, or working with XML-based formats like RSS, Atom, or SOAP. zek uses sampling to infer types, so providing representative XML with all possible fields yields the best results.

参数

-c
Compact output (minimize struct tags)
-e
Add XMLName field to struct
-n _name_
Use specified struct name (default: derived from root element)
-p
Add xml.Name XMLName field for precise marshaling
-t
Include type comments in output
-x
Emit only the struct, no package declaration
-max-examples _n_
Maximum examples to show in comments
-version
Print version and exit

FAQ

What is the zek command used for?

zek generates Go struct definitions from XML documents. It analyzes the XML structure and produces type-safe Go code that can unmarshal (and marshal) that XML format. Given an XML file, zek infers the structure and generates appropriate Go types with proper xml struct tags. It handles nested elements, attributes, repeated elements (slices), and mixed content. This is useful for quickly creating Go types for consuming XML APIs, parsing XML data files, or working with XML-based formats like RSS, Atom, or SOAP. zek uses sampling to infer types, so providing representative XML with all possible fields yields the best results.

How do I run a basic zek example?

Run `zek [file.xml]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -c do in zek?

Compact output (minimize struct tags)