Skip to content

Commit

Permalink
Work in progress: implement DTD in metaschema parser
Browse files Browse the repository at this point in the history
Note DTD implementation in golang xml parser is not straight forward yet
doable.
  • Loading branch information
isimluk committed Mar 11, 2024
1 parent ba9e089 commit 7a4bbd1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
4 changes: 2 additions & 2 deletions metaschema/generate.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package metaschema

import (
"encoding/xml"
"fmt"
"io"
"os"
"strings"

"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 {
Expand Down Expand Up @@ -46,7 +46,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)
Expand Down
26 changes: 26 additions & 0 deletions pkg/xml_dtd/decoder.go
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit 7a4bbd1

Please sign in to comment.