From d11b2296910842f71bf791ed9f81c9a22537a31a Mon Sep 17 00:00:00 2001 From: Jason Streifling Date: Thu, 17 Oct 2024 18:57:43 +0200 Subject: [PATCH] No more undefined content in link and category It seems that undefined content is only mentioned in RFC4287 because link and category are elements and those usually need some content. --- category.go | 23 +++++------------------ link.go | 17 ++--------------- 2 files changed, 7 insertions(+), 33 deletions(-) diff --git a/category.go b/category.go index 34febdc..829663b 100644 --- a/category.go +++ b/category.go @@ -8,21 +8,14 @@ import ( type Category struct { *CommonAttributes - Content string `xml:",chardata"` // undefinedContent in RFC4287 - Term string `xml:"term,attr"` - Scheme IRI `xml:"scheme,attr,omitempty"` - Label string `xml:"label,attr,omitempty"` + 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, content string) (*Category, error) { - if content != "" { - if !isValidXML(content) { - return nil, fmt.Errorf("%v not valid XML", content) - } - } - - return &Category{Term: term, Content: content}, nil +func NewCategory(term string) *Category { + return &Category{Term: term} } // SetLabel sets the label of the Category. @@ -47,11 +40,5 @@ func (c *Category) Check() error { return fmt.Errorf("label attribute %v of category not correctly escaped", c.Label) } - if c.Content != "" { - if !isValidXML(c.Content) { - return fmt.Errorf("content element %v of category not valid XML", c.Content) - } - } - return nil } diff --git a/link.go b/link.go index 9c0d92d..8b49d26 100644 --- a/link.go +++ b/link.go @@ -9,7 +9,6 @@ import ( type Link struct { *CommonAttributes Title string `xml:"title,attr,omitempty"` - Content string `xml:",chardata"` // undefinedContent in RFC4287 Href IRI `xml:"href,attr"` Rel string `xml:"rel,attr,omitempty"` Type MediaType `xml:"type,attr,omitempty"` @@ -18,14 +17,8 @@ type Link struct { } // NewLink creates a new Link. It returns a *Link and an error. -func NewLink(href, content string) (*Link, error) { - if content != "" { - if !isValidXML(content) { - return nil, fmt.Errorf("%v not valid XML", content) - } - } - - return &Link{Href: IRI(href), Content: content}, nil +func NewLink(href, content string) *Link { + return &Link{Href: IRI(href)} } // Check checks the Link for incompatibilities with RFC4287. It returns an @@ -57,12 +50,6 @@ func (l *Link) Check() error { } } - if l.Content != "" { - if !isValidXML(l.Content) { - return fmt.Errorf("content element %v of link not valid XML", l.Content) - } - } - return nil }