diff --git a/configuration.go b/configuration.go index d35aa1ae..09843f68 100644 --- a/configuration.go +++ b/configuration.go @@ -1,18 +1,31 @@ package mdclasses import ( - "encoding/xml" "github.com/khorevaa/logos" + "github.com/v8platform/mdclasses/encoding/xml" ) var log = logos.New("github.com/v8platform/mdclasses").Sugar() +type Mdclass struct { + xml.Name + value string +} + +type Name struct { + xml.Name + value string +} + type Configuration struct { - XMLName xml.Name `xml:"Configuration"` - Mdclass string `xml:"mdclass,attr"` - Uuid string `xml:"uuid,attr"` - Name string `xml:"name"` - Synonym ValueTypeRef `xml:"synonym"` + XMLName xml.Name `xml:"mdclass Configuration"` + Mdclass xml.Attr `xml:"mdclass,attr"` + Uuid string `xml:"uuid,attr"` + Name string `xml:"name"` + Synonym struct { + Key string `xml:"key"` + Value string `xml:"value"` + } `xml:"synonym"` ContainedObjects []struct { ClassId string `xml:"classId,attr,allowempty"` ObjectId string `xml:"objectId,attr,allowempty"` @@ -114,6 +127,44 @@ type Configuration struct { Tasks []string `xml:"tasks"` } +const ConfigurationFile = "Configuration.mdo" + +func (conf *Name) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error { + panic("implement me") +} + +func (conf *Mdclass) MarshalXMLAttr(name xml.Name) (xml.Attr, error) { + //pp.Println(name) + return xml.Attr{ + conf.Name, + conf.value, + }, nil +} + +func (conf *Mdclass) UnmarshalXMLAttr(attr xml.Attr) error { + + conf.Name = attr.Name + conf.value = attr.Value + + return nil +} + +func (conf *Name) MarshalXMLAttr(name xml.Name) (xml.Attr, error) { + //pp.Println(name) + return xml.Attr{ + conf.Name, + conf.value, + }, nil +} + +func (conf *Name) UnmarshalXMLAttr(attr xml.Attr) error { + + conf.Name = attr.Name + conf.value = attr.Value + + return nil +} + func (conf *Configuration) Unpack(cfg UnpackConfig) error { for _, name := range conf.SubsystemsNames { diff --git a/encoding/xml/marshal.go b/encoding/xml/marshal.go index e831b575..2e4bc360 100644 --- a/encoding/xml/marshal.go +++ b/encoding/xml/marshal.go @@ -353,7 +353,8 @@ func (p *printer) createAttrPrefix(url string) string { // (('X'|'x') ('M'|'m') ('L'|'l')) // See Section 2.3 of https://www.w3.org/TR/REC-xml/ if len(prefix) >= 3 && strings.EqualFold(prefix[:3], "xml") { - prefix = "_" + prefix + // prefix = "_" + prefix + return prefix } if p.attrNS[prefix] != "" { // Name is taken. Find a better one. @@ -722,13 +723,12 @@ func (p *printer) writeStart(start *StartElement, selfClosing bool) error { } p.WriteByte('<') - p.WriteString(start.Name.Local) if start.Name.Space != "" { - p.WriteString(` xmlns="`) p.EscapeString(start.Name.Space) - p.WriteByte('"') + p.WriteByte(':') } + p.WriteString(start.Name.Local) // Attributes for _, attr := range start.Attr { @@ -772,7 +772,13 @@ func (p *printer) writeEnd(name Name) error { p.writeIndent(-1) p.WriteByte('<') p.WriteByte('/') + if name.Space != "" { + p.EscapeString(name.Space) + p.WriteByte(':') + } + p.WriteString(name.Local) + p.WriteByte('>') p.popPrefix() return nil diff --git a/encoding/xml/xml.go b/encoding/xml/xml.go index cc055f64..ff5d9ace 100644 --- a/encoding/xml/xml.go +++ b/encoding/xml/xml.go @@ -359,9 +359,10 @@ func (d *Decoder) translate(n *Name, isElementName bool) { case n.Space == "" && n.Local == xmlnsPrefix: return } - if v, ok := d.ns[n.Space]; ok { - n.Space = v - } else if n.Space == "" { + // if v, ok := d.ns[n.Space]; ok { + // n.Space = v + // } else + if n.Space == "" { n.Space = d.DefaultSpace } } diff --git a/go.mod b/go.mod index 94c0c8f7..ccb09c02 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,10 @@ module github.com/v8platform/mdclasses go 1.16 require ( - github.com/khorevaa/logos v0.9.8 + github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88 // indirect + github.com/k0kubun/pp v3.0.1+incompatible + github.com/mattn/go-colorable v0.1.8 // indirect github.com/pkg/errors v0.9.1 + github.com/khorevaa/logos v0.9.8 + ) diff --git a/go.sum b/go.sum index 6c94e563..10aa710d 100644 --- a/go.sum +++ b/go.sum @@ -19,8 +19,19 @@ github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88 h1:uC1QfSlInpQF+M0ao65imhwqKnz3Q2z/d8PWZRMQvDM= +github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88/go.mod h1:3w7q1U84EfirKl04SVQ/s7nPm1ZPhiXd34z40TNz36k= +github.com/k0kubun/pp v3.0.1+incompatible h1:3tqvf7QgUnZ5tXO6pNAZlrvHgl6DvifjDrd9g2S9Z40= +github.com/k0kubun/pp v3.0.1+incompatible/go.mod h1:GWse8YhT0p8pT4ir3ZgBbfZild3tgzSScAn6HmfYukg= +github.com/mattn/go-colorable v0.1.8 h1:c1ghPdyEDarC70ftn0y+A/Ee++9zz8ljHG1b13eJ0s8= +github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= +github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY= +github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae h1:/WDfKMnPU+m5M4xB+6x4kaepxRw6jWvR5iDRdvjHgy8= +golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= diff --git a/mdclasses.go b/mdclasses.go index caa1a7bc..cef6b040 100644 --- a/mdclasses.go +++ b/mdclasses.go @@ -1,5 +1,10 @@ package mdclasses +import ( + "fmt" + "github.com/v8platform/mdclasses/encoding/xml" +) + func UnpackConfiguration(dir string) (Configuration, error) { cfg := NewUnpackConfig("Configuration", dir) @@ -10,6 +15,13 @@ func UnpackConfiguration(dir string) (Configuration, error) { return Configuration{}, err } + bytes, err := xml.Marshal(conf) + if err != nil { + return Configuration{}, err + } + str := string(bytes) + fmt.Println(str) + return conf, nil } diff --git a/unpack.go b/unpack.go index d80eb541..1d2938ba 100644 --- a/unpack.go +++ b/unpack.go @@ -1,9 +1,9 @@ package mdclasses import ( - "encoding/xml" "fmt" "github.com/pkg/errors" + "github.com/v8platform/mdclasses/encoding/xml" "io/ioutil" "os" "path/filepath"