From 4beb1e82dad9bcf66a5ea569b8a7d20d039a893d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Luka=C5=A1=C3=ADk?= Date: Tue, 8 Nov 2022 20:06:17 +0000 Subject: [PATCH] Work in progress: implement DTD in metaschema parser Note DTD implementation in golang xml parser is not straight forward yet doable. --- metaschema/generate.go | 4 ++-- pkg/xml_dtd/decoder.go | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 pkg/xml_dtd/decoder.go diff --git a/metaschema/generate.go b/metaschema/generate.go index e334410..4bbdd8e 100644 --- a/metaschema/generate.go +++ b/metaschema/generate.go @@ -1,7 +1,6 @@ package metaschema import ( - "encoding/xml" "fmt" "io" "io/ioutil" @@ -10,6 +9,7 @@ import ( "github.com/gocomply/metaschema/metaschema/parser" "github.com/gocomply/metaschema/metaschema/templates" + "github.com/gocomply/metaschema/pkg/xml_dtd" ) func Generate(metaschemaDir, goModule, outputDir string) error { @@ -47,7 +47,7 @@ func Generate(metaschemaDir, goModule, outputDir string) error { func decode(metaschemaDir, goModule string, r io.Reader) (*parser.Metaschema, error) { var meta parser.Metaschema - d := xml.NewDecoder(r) + d := xml_dtd.NewDecoder(r) if err := d.Decode(&meta); err != nil { return nil, fmt.Errorf("Error decoding metaschema: %s", err) diff --git a/pkg/xml_dtd/decoder.go b/pkg/xml_dtd/decoder.go new file mode 100644 index 0000000..d8dd035 --- /dev/null +++ b/pkg/xml_dtd/decoder.go @@ -0,0 +1,26 @@ +package xml_dtd + +import ( + "encoding/xml" + "io" +) + +type Decoder struct { + *xml.Decoder +} + +func NewDecoder(r io.Reader) *Decoder { + dtd := &Decoder{ + Decoder: xml.NewDecoder(r), + } + dtd.Entity = map[string]string{ + "allowed-values-control-group-property-name": "TODO-FIX-THIS", + "allowed-values-component_inventory-item_property-name": "TODO-FIX-THIS", + "allowed-values-component_component_property-name": "TODO-FIX-THIS", + } + return dtd +} + +func (d *Decoder) Decode(v interface{}) error { + return d.Decoder.Decode(v) +}