package atomfeed import ( "errors" "fmt" "html" ) type Category struct { *CommonAttributes Content Content `xml:"content"` // undefinedContent in RFC4287 Term string `xml:"term,attr"` Scheme IRI `xml:"scheme,attr,omitempty"` Label string `xml:"label,attr,omitempty"` } func NewCategory(term string) (*Category, error) { content, err := NewContent(InlineText, "", "") if err != nil { return nil, fmt.Errorf("error creating content element: %v", err) } return &Category{Term: term, Content: content}, nil } func (c *Category) SetLabel(label string) { c.Label = html.UnescapeString(label) } func (c *Category) Check() error { if c.Term == "" { return errors.New("term attribute of category empty") } if c.Scheme != "" { if !isValidIRI(c.Scheme) { return fmt.Errorf("scheme attribute %v of category not correctly formatted", c.Scheme) } } if !isCorrectlyEscaped(c.Label) { return fmt.Errorf("label attribute %v of category not correctly escaped", c.Label) } if c.Content == nil { return errors.New("no content element of category") } else { if err := c.Content.Check(); err != nil { return fmt.Errorf("content element of category: %v", err) } } return nil }