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
import (
"encoding/xml"
"errors"
"fmt"
"html"
)
type Category struct {
XMLName xml.Name `xml:"category"`
*CommonAttributes
Term string `xml:"term,attr"`
Scheme IRI `xml:"scheme,attr,omitempty"`

View File

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

View File

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

View File

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

18
feed.go
View File

@ -10,20 +10,20 @@ import (
type Feed struct {
XMLName xml.Name `xml:"http://www.w3.org/2005/Atom feed"`
*CommonAttributes
Authors []*Person `xml:"author,omitempty"`
Categories []*Category `xml:"category,omitempty"`
Contributors []*Person `xml:"contributor,omitempty"`
Generator *Generator `xml:"generator,omitempty"`
Icon *Icon `xml:"icon,omitempty"`
ID *ID `xml:"id"`
Links []*Link `xml:"link,omitempty"`
Logo *Logo `xml:"logo,omitempty"`
Authors []*Person `xml:"author,omitempty"`
Categories []*Category `xml:",omitempty"`
Contributors []*Person `xml:"contributor,omitempty"`
Generator *Generator `xml:",omitempty"`
Icon *Icon `xml:",omitempty"`
ID *ID
Links []*Link `xml:",omitempty"`
Logo *Logo `xml:",omitempty"`
Rights Text `xml:"rights,omitempty"`
Subtitle Text `xml:"subtitle,omitempty"`
Title Text `xml:"title"`
Updated *Date `xml:"updated"`
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.

View File

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

View File

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

2
id.go
View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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