encoding/xml
to your project.
You may want to start reading blog introduction to this project.
Did you ever got to implement XML parser? Perhaps for atom, or scap? You may have got XSD (XML Schema Definition) files to verify adherence to given xml application? Wouldn't it be cool to automatically generate XML parser based on XSD definition? That's exactly what we are up to here.
go install github.com/gocomply/xsd2go/cli/gocomply_xsd2go@latest
gocomply_xsd2go convert --help
NAME:
gocomply_xsd2go convert - convert XSD to golang code to parse xml files generated by given xsd
USAGE:
gocomply_xsd2go convert [command options] XSD-FILE GO-MODULE-IMPORT OUTPUT-DIR
OPTIONS:
--xmlns-override value Allows to explicitly set gopackage name for given XMLNS. Example: --xmlns-override='http://www.w3.org/2000/09/xmldsig#=xml_signatures'
# Acquire latest some XSD file you want to convert - for instance XCCDF 1.2
git clone --depth 1 https://github.com/openscap/openscap
# Parse XSD schema and generate golang structs
./gocomply_xsd2go convert \
--xmlns-override=http://cpe.mitre.org/language/2.0=cpe_language \
.scap_schemas/schemas/xccdf/1.2/xccdf_1.2.xsd \
github.com/gocomply/scap pkg/scap/models