package atom import ( "encoding/xml" "fmt" ) type Category struct { XMLName xml.Name `xml:"category"` *CommonAttributes Term string `xml:"term,attr"` Scheme string `xml:"scheme,attr,omitempty"` // IRI Label string `xml:"label,attr,omitempty"` // Must be unescaped } // NewCategory creates a new Category. It returns a *Category. func NewCategory(term string) *Category { return &Category{ CommonAttributes: newCommonAttributes(), Term: term, } } // Check checks the Category for incompatibilities with RFC4287. It returns an // error. func (c *Category) Check() error { if c.Term == "" { return fmt.Errorf("term attribute of category %v empty", c) } if c.Scheme != "" { if !isValidIRI(c.Scheme) { return fmt.Errorf("scheme attribute of category %v not correctly formatted", c) } } if !isCorrectlyEscaped(c.Label) { return fmt.Errorf("label attribute of category %v not correctly escaped", c) } return nil }