Skip to content

Commit

Permalink
Start processing xsd:complexContent/xsd:attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
isimluk committed May 31, 2020
1 parent e651948 commit fc46b26
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
14 changes: 14 additions & 0 deletions pkg/xsd/content.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import (
"encoding/xml"
)

type GenericContent interface {
Attributes() []Attribute
compile(*Schema)
}
type SimpleContent struct {
XMLName xml.Name `xml:"http://www.w3.org/2001/XMLSchema simpleContent"`
Extension *Extension `xml:"extension"`
Expand All @@ -16,6 +20,9 @@ func (sc *SimpleContent) Attributes() []Attribute {
return []Attribute{}
}

func (sc *SimpleContent) compile(sch *Schema) {
}

type Extension struct {
XMLName xml.Name `xml:"http://www.w3.org/2001/XMLSchema extension"`
Base string `xml:"base,attr"`
Expand All @@ -28,6 +35,13 @@ type ComplexContent struct {
schema *Schema `xml:"-"`
}

func (cc *ComplexContent) Attributes() []Attribute {
if cc.Extension != nil {
return cc.Extension.Attributes
}
return []Attribute{}
}

func (c *ComplexContent) compile(sch *Schema) {
c.schema = sch
}
23 changes: 16 additions & 7 deletions pkg/xsd/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ type ComplexType struct {
schema *Schema `xml:"-"`
SimpleContent *SimpleContent `xml:"simpleContent"`
ComplexContent *ComplexContent `xml:"complexContent"`
content GenericContent `xml:"-"`
}

func (ct *ComplexType) Attributes() []Attribute {
if ct.SimpleContent != nil {
return ct.SimpleContent.Attributes()
if ct.content != nil {
return ct.content.Attributes()
}
return ct.AttributesDirect
}
Expand Down Expand Up @@ -71,16 +72,24 @@ func (ct *ComplexType) compile(sch *Schema) {
// Second GoName may be different depending on the DuplicateCount
goNames[attribute.GoName()] = count
}

if ct.ComplexContent != nil {
ct.ComplexContent.compile(sch)
ct.content = ct.ComplexContent
if ct.SimpleContent != nil {
panic("Not implemented: xsd:complexType " + ct.Name + " defines xsd:simpleContent and xsd:complexContent together")
}
} else if ct.SimpleContent != nil {
ct.content = ct.SimpleContent
}

if ct.ComplexContent != nil && ct.SimpleContent != nil {
panic("Not implemented: xsd:complexType " + ct.Name + " defines xsd:simpleContent and xsd:complexContent together")
}
if (ct.ComplexContent != nil || ct.SimpleContent != nil) && len(ct.AttributesDirect) > 1 {
if (ct.content != nil) && len(ct.AttributesDirect) > 1 {
panic("Not implemented: xsd:complexType " + ct.Name + " defines direct attribute and xsd:*Content")
}

if ct.content != nil {
ct.content.compile(sch)
}

}

type SimpleType struct {
Expand Down

0 comments on commit fc46b26

Please # to comment.