Properly use xml names

This commit is contained in:
Jason Streifling 2024-10-17 20:10:18 +02:00
parent 26e0c99150
commit 9c38048bd2
15 changed files with 51 additions and 23 deletions

View File

@ -1,12 +1,14 @@
package atom package atom
import ( import (
"encoding/xml"
"errors" "errors"
"fmt" "fmt"
"html" "html"
) )
type Category struct { type Category struct {
XMLName xml.Name `xml:"category"`
*CommonAttributes *CommonAttributes
Term string `xml:"term,attr"` Term string `xml:"term,attr"`
Scheme IRI `xml:"scheme,attr,omitempty"` Scheme IRI `xml:"scheme,attr,omitempty"`

View File

@ -1,6 +1,7 @@
package atom package atom
import ( import (
"encoding/xml"
"errors" "errors"
"fmt" "fmt"
"strings" "strings"
@ -12,16 +13,17 @@ import (
// a non-empty atom:summary element when the entry contains no atom:content // a non-empty atom:summary element when the entry contains no atom:content
// element. // element.
type Entry struct { type Entry struct {
XMLName xml.Name `xml:"entry"`
*CommonAttributes *CommonAttributes
Authors []*Person `xml:"author,omitempty"` Authors []*Person `xml:"author,omitempty"`
Categories []*Category `xml:"category,omitempty"` Categories []*Category `xml:",omitempty"`
Content Content `xml:"content,omitempty"` Content Content `xml:",omitempty"`
Contributors []*Person `xml:"contributors,omitempty"` Contributors []*Person `xml:"contributors,omitempty"`
ID *ID `xml:"id"` ID *ID
Links []*Link `xml:"link,omitempty"` Links []*Link `xml:",omitempty"`
Published *Date `xml:"published,omitempty"` Published *Date `xml:"published,omitempty"`
Rights Text `xml:"rights,omitempty"` Rights Text `xml:"rights,omitempty"`
Source *Source `xml:"source,omitempty"` Source *Source `xml:",omitempty"`
Summary Text `xml:"summary,omitempty"` Summary Text `xml:"summary,omitempty"`
Title Text `xml:"title"` Title Text `xml:"title"`
Updated *Date `xml:"updated"` Updated *Date `xml:"updated"`

View File

@ -5,6 +5,7 @@ import (
"errors" "errors"
) )
// TODO: Is this really correct?
type ExtensionAttribute struct { type ExtensionAttribute struct {
Value any `xml:",attr"` Value any `xml:",attr"`
XMLName xml.Name XMLName xml.Name

View File

@ -5,6 +5,7 @@ import (
"errors" "errors"
) )
// TODO: Is this really correct?
type ExtensionElement struct { type ExtensionElement struct {
Value any `xml:",innerxml"` Value any `xml:",innerxml"`
XMLName xml.Name XMLName xml.Name

14
feed.go
View File

@ -11,19 +11,19 @@ type Feed struct {
XMLName xml.Name `xml:"http://www.w3.org/2005/Atom feed"` XMLName xml.Name `xml:"http://www.w3.org/2005/Atom feed"`
*CommonAttributes *CommonAttributes
Authors []*Person `xml:"author,omitempty"` Authors []*Person `xml:"author,omitempty"`
Categories []*Category `xml:"category,omitempty"` Categories []*Category `xml:",omitempty"`
Contributors []*Person `xml:"contributor,omitempty"` Contributors []*Person `xml:"contributor,omitempty"`
Generator *Generator `xml:"generator,omitempty"` Generator *Generator `xml:",omitempty"`
Icon *Icon `xml:"icon,omitempty"` Icon *Icon `xml:",omitempty"`
ID *ID `xml:"id"` ID *ID
Links []*Link `xml:"link,omitempty"` Links []*Link `xml:",omitempty"`
Logo *Logo `xml:"logo,omitempty"` Logo *Logo `xml:",omitempty"`
Rights Text `xml:"rights,omitempty"` Rights Text `xml:"rights,omitempty"`
Subtitle Text `xml:"subtitle,omitempty"` Subtitle Text `xml:"subtitle,omitempty"`
Title Text `xml:"title"` Title Text `xml:"title"`
Updated *Date `xml:"updated"` Updated *Date `xml:"updated"`
Extensions []*ExtensionElement `xml:",any,omitempty"` Extensions []*ExtensionElement `xml:",any,omitempty"`
Entries []*Entry `xml:"entry,omitempty"` Entries []*Entry `xml:",omitempty"`
} }
// NewFeed creates a new Feed. It returns a *Feed and an error. // NewFeed creates a new Feed. It returns a *Feed and an error.

View File

@ -1,12 +1,14 @@
package atom package atom
import ( import (
"encoding/xml"
"errors" "errors"
"fmt" "fmt"
"html" "html"
) )
type Generator struct { type Generator struct {
XMLName xml.Name `xml:"generator"`
*CommonAttributes *CommonAttributes
URI IRI `xml:"uri,attr,omitempty"` URI IRI `xml:"uri,attr,omitempty"`
Version string `xml:"version,attr,omitempty"` Version string `xml:"version,attr,omitempty"`

View File

@ -1,11 +1,13 @@
package atom package atom
import ( import (
"encoding/xml"
"errors" "errors"
"fmt" "fmt"
) )
type Icon struct { type Icon struct {
XMLName xml.Name `xml:"icon"`
*CommonAttributes *CommonAttributes
URI IRI `xml:",chardata"` URI IRI `xml:",chardata"`
} }

2
id.go
View File

@ -1,11 +1,13 @@
package atom package atom
import ( import (
"encoding/xml"
"errors" "errors"
"fmt" "fmt"
) )
type ID struct { type ID struct {
XMLName xml.Name `xml:"id"`
*CommonAttributes *CommonAttributes
URI IRI `xml:",chardata"` URI IRI `xml:",chardata"`
} }

View File

@ -1,12 +1,14 @@
package atom package atom
import ( import (
"encoding/xml"
"errors" "errors"
"fmt" "fmt"
"mime" "mime"
) )
type InlineOtherContent struct { type InlineOtherContent struct {
XMLName xml.Name `xml:"content"`
*CommonAttributes *CommonAttributes
AnyElement any `xml:",chardata"` AnyElement any `xml:",chardata"`
Type MediaType `xml:"type,attr,omitempty"` Type MediaType `xml:"type,attr,omitempty"`

View File

@ -1,11 +1,13 @@
package atom package atom
import ( import (
"encoding/xml"
"errors" "errors"
"fmt" "fmt"
) )
type InlineTextContent struct { type InlineTextContent struct {
XMLName xml.Name `xml:"content"`
*CommonAttributes *CommonAttributes
Type string `xml:"type,attr,omitempty"` // Must be text or html Type string `xml:"type,attr,omitempty"` // Must be text or html
Text string `xml:",chardata"` Text string `xml:",chardata"`

View File

@ -1,11 +1,13 @@
package atom package atom
import ( import (
"encoding/xml"
"errors" "errors"
"fmt" "fmt"
) )
type InlineXHTMLContent struct { type InlineXHTMLContent struct {
XMLName xml.Name `xml:"content"`
*CommonAttributes *CommonAttributes
XHTMLDiv *XHTMLDiv XHTMLDiv *XHTMLDiv
Type string `xml:"type,attr"` Type string `xml:"type,attr"`

View File

@ -1,12 +1,14 @@
package atom package atom
import ( import (
"encoding/xml"
"errors" "errors"
"fmt" "fmt"
"strings" "strings"
) )
type Link struct { type Link struct {
XMLName xml.Name `xml:"link"`
*CommonAttributes *CommonAttributes
Title string `xml:"title,attr,omitempty"` Title string `xml:"title,attr,omitempty"`
Href IRI `xml:"href,attr"` Href IRI `xml:"href,attr"`

View File

@ -1,11 +1,13 @@
package atom package atom
import ( import (
"encoding/xml"
"errors" "errors"
"fmt" "fmt"
) )
type Logo struct { type Logo struct {
XMLName xml.Name `xml:"logo"`
*CommonAttributes *CommonAttributes
URI IRI `xml:",chardata"` URI IRI `xml:",chardata"`
} }

View File

@ -1,12 +1,14 @@
package atom package atom
import ( import (
"encoding/xml"
"errors" "errors"
"fmt" "fmt"
"mime" "mime"
) )
type OutOfLineContent struct { type OutOfLineContent struct {
XMLName xml.Name `xml:"content"`
*CommonAttributes *CommonAttributes
Type MediaType `xml:"type,attr,omitempty"` Type MediaType `xml:"type,attr,omitempty"`
SRC IRI `xml:"src,attr"` SRC IRI `xml:"src,attr"`

View File

@ -1,17 +1,21 @@
package atom package atom
import "fmt" import (
"encoding/xml"
"fmt"
)
type Source struct { type Source struct {
XMLName xml.Name `xml:"source"`
*CommonAttributes *CommonAttributes
Authors []*Person `xml:"author,omitempty"` Authors []*Person `xml:"author,omitempty"`
Categories []*Category `xml:"category,omitempty"` Categories []*Category `xml:",omitempty"`
Contributors []*Person `xml:"contributor,omitempty"` Contributors []*Person `xml:"contributor,omitempty"`
Generator *Generator `xml:"generator,omitempty"` Generator *Generator `xml:",omitempty"`
Icon *Icon `xml:"icon,omitempty"` Icon *Icon `xml:",omitempty"`
ID *ID `xml:"id,omitempty"` ID *ID `xml:",omitempty"`
Links []*Link `xml:"link,omitempty"` Links []*Link `xml:",omitempty"`
Logo *Logo `xml:"logo,omitempty"` Logo *Logo `xml:",omitempty"`
Rights Text `xml:"rights,omitempty"` Rights Text `xml:"rights,omitempty"`
Subtitle Text `xml:"subtitle,omitempty"` Subtitle Text `xml:"subtitle,omitempty"`
Title Text `xml:"title,omitempty"` Title Text `xml:"title,omitempty"`