Use built-in xml attributes
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
package atom
|
||||
|
||||
import "fmt"
|
||||
import (
|
||||
"encoding/xml"
|
||||
)
|
||||
|
||||
type CommonAttributes struct {
|
||||
Base IRI `xml:"base,attr,omitempty"`
|
||||
Lang LanguageTag `xml:"lang,attr,omitempty"`
|
||||
UndefinedAttributes []*ExtensionAttribute `xml:",attr"`
|
||||
Base IRI `xml:"base,attr,omitempty"`
|
||||
Lang LanguageTag `xml:"lang,attr,omitempty"`
|
||||
UndefinedAttributes []*xml.Attr `xml:",attr,omitempty"`
|
||||
}
|
||||
|
||||
// NewCommonAttributes creates a new set of CommonAttributes. It returns a
|
||||
@@ -15,23 +17,11 @@ func NewCommonAttributes() *CommonAttributes {
|
||||
}
|
||||
|
||||
// AddExtensionAttribute adds the ExtensionAttribute to the CommonAttributes.
|
||||
func (c *CommonAttributes) AddExtensionAttribute(e *ExtensionAttribute) {
|
||||
func (c *CommonAttributes) AddExtensionAttribute(name, value string) {
|
||||
if c.UndefinedAttributes == nil {
|
||||
c.UndefinedAttributes = make([]*ExtensionAttribute, 1)
|
||||
c.UndefinedAttributes[0] = e
|
||||
c.UndefinedAttributes = make([]*xml.Attr, 1)
|
||||
c.UndefinedAttributes[0] = &xml.Attr{Name: xml.Name{Local: name}, Value: value}
|
||||
} else {
|
||||
c.UndefinedAttributes = append(c.UndefinedAttributes, e)
|
||||
c.UndefinedAttributes = append(c.UndefinedAttributes, &xml.Attr{Name: xml.Name{Local: name}, Value: value})
|
||||
}
|
||||
}
|
||||
|
||||
// Check checks the CommonAttributes for incompatibilities with RFC4287. It
|
||||
// returns an error.
|
||||
func (c *CommonAttributes) Check() error {
|
||||
for i, a := range c.UndefinedAttributes {
|
||||
if err := a.Check(); err != nil {
|
||||
return fmt.Errorf("extension attribute %v of common attributes: %v", i, err)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user