Make undefined content in category and link type string

This commit is contained in:
2024-10-17 18:11:06 +02:00
parent 4b97bf7fdc
commit 705b651f08
2 changed files with 11 additions and 29 deletions

View File

@@ -8,19 +8,14 @@ import (
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"`
Content string `xml:",any"` // undefinedContent in RFC4287
Term string `xml:"term,attr"`
Scheme IRI `xml:"scheme,attr,omitempty"`
Label string `xml:"label,attr,omitempty"`
}
// NewCategory creates a new Category. It returns a *Category and an error.
func NewCategory(term string) (*Category, error) {
content, err := NewContent(InlineText, "", "")
if err != nil {
return nil, fmt.Errorf("error creating content element: %v", err)
}
func NewCategory(term, content string) (*Category, error) {
return &Category{Term: term, Content: content}, nil
}
@@ -46,12 +41,8 @@ func (c *Category) Check() error {
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)
}
if c.Content == "" {
return errors.New("content element of category empty")
}
return nil