diff --git a/commonAttributes.go b/commonAttributes.go index 2f13977..3c6473b 100644 --- a/commonAttributes.go +++ b/commonAttributes.go @@ -8,6 +8,22 @@ type CommonAttributes struct { UndefinedAttributes []*ExtensionAttribute `xml:",any"` } +// NewCommonAttributes creates a new set of CommonAttributes. It returns a +// *CommonAttributes. +func NewCommonAttributes() *CommonAttributes { + return new(CommonAttributes) +} + +// AddExtensionAttribute adds the ExtensionAttribute to the CommonAttributes. +func (c *CommonAttributes) AddExtensionAttribute(e *ExtensionAttribute) { + if c.UndefinedAttributes == nil { + c.UndefinedAttributes = make([]*ExtensionAttribute, 1) + c.UndefinedAttributes[0] = e + } else { + c.UndefinedAttributes = append(c.UndefinedAttributes, e) + } +} + // Check checks the CommonAttributes for incompatibilities with RFC4287. It // returns an error. func (c *CommonAttributes) Check() error { diff --git a/extensionAttribute.go b/extensionAttribute.go index d6fccb4..8e38700 100644 --- a/extensionAttribute.go +++ b/extensionAttribute.go @@ -1,20 +1,24 @@ package atom import ( - "encoding/xml" "errors" + "fmt" ) -// TODO: Is this really correct? type ExtensionAttribute struct { - Value any `xml:",attr"` - XMLName xml.Name + Attr string `xml:",attr"` +} + +// NewExtensionAttribute creates a new ExtensionAttribute. It returns a +// *ExtensionAttribute. +func NewExtensionAttribute(name, value string) *ExtensionAttribute { + return &ExtensionAttribute{Attr: fmt.Sprint(name, `="`, value, `"`)} } // Check checks the ExtensionAttribute for incompatibilities with RFC4287. It // returns an error. func (e *ExtensionAttribute) Check() error { - if e.Value == nil { + if e.Attr == "" { return errors.New("value element of extension attribute empty") } diff --git a/extensionElement.go b/extensionElement.go index 77574b3..1f6c1d0 100644 --- a/extensionElement.go +++ b/extensionElement.go @@ -5,7 +5,6 @@ import ( "errors" ) -// TODO: Is this really correct? type ExtensionElement struct { Value any `xml:",innerxml"` XMLName xml.Name