diff --git a/text.go b/text.go index 9bd08ad..860e0b0 100644 --- a/text.go +++ b/text.go @@ -17,7 +17,13 @@ func NewText(textType, content string) (Text, error) { case "html": return &PlainText{Type: textType, Text: html.EscapeString(content)}, nil case "xhtml": - return &XHTMLText{Type: textType, XHTMLDiv: content}, nil + return &XHTMLText{ + Type: textType, + XHTMLDiv: XHTMLDiv{ + XMLNS: "http://www.w3.org/1999/xhtml", + Content: content, + }, + }, nil case "": return &PlainText{Type: "text", Text: content}, nil default: diff --git a/xhtmlText.go b/xhtmlText.go index 59139a4..9965738 100644 --- a/xhtmlText.go +++ b/xhtmlText.go @@ -1,11 +1,20 @@ package atomfeed -import "errors" +import ( + "encoding/xml" + "errors" +) + +type XHTMLDiv struct { + XMLName xml.Name `xml:"div"` + XMLNS string `xml:"xmlns,attr"` + Content string `xml:",innerxml"` +} type XHTMLText struct { *CommonAttributes Type string `xml:"type,attr"` // Must be xhtml - XHTMLDiv string `xml:"div"` + XHTMLDiv XHTMLDiv } func (x *XHTMLText) IsText() bool { return true } @@ -15,8 +24,8 @@ func (x *XHTMLText) Check() error { return errors.New("type attribute of xhtml text must be xhtml") } - if x.XHTMLDiv == "" { - return errors.New("xhtmlDiv element of xhtml text empty") + if x.XHTMLDiv.XMLNS != "http://www.w3.org/1999/xhtml" { + return errors.New("xmlns attribute of xhtml text must be http://www.w3.org/1999/xhtml") } return nil