Create xhtmlDiv.go
This commit is contained in:
parent
705b651f08
commit
040d7a6b7b
30
xhtmlDiv.go
Normal file
30
xhtmlDiv.go
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
package atom
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/xml"
|
||||||
|
"errors"
|
||||||
|
)
|
||||||
|
|
||||||
|
type XHTMLDiv struct {
|
||||||
|
XMLName xml.Name `xml:"div"`
|
||||||
|
XMLNS string `xml:"xmlns,attr"`
|
||||||
|
Content string `xml:",innerxml"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewXHTMLDiv creates a new XHTMLDiv. It returns a *XHTMLDiv.
|
||||||
|
func NewXHTMLDiv(content string) *XHTMLDiv {
|
||||||
|
return &XHTMLDiv{
|
||||||
|
XMLNS: "http://www.w3.org/1999/xhtml",
|
||||||
|
Content: content,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check checks the XHTMLDiv for incompatibilities with RFC4287. It returns an
|
||||||
|
// error.
|
||||||
|
func (x *XHTMLDiv) Check() error {
|
||||||
|
if x.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
|
||||||
|
}
|
12
xhtmlText.go
12
xhtmlText.go
@ -1,16 +1,10 @@
|
|||||||
package atom
|
package atom
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/xml"
|
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
type XHTMLDiv struct {
|
|
||||||
XMLName xml.Name `xml:"div"`
|
|
||||||
XMLNS string `xml:"xmlns,attr"`
|
|
||||||
Content string `xml:",innerxml"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type XHTMLText struct {
|
type XHTMLText struct {
|
||||||
*CommonAttributes
|
*CommonAttributes
|
||||||
Type string `xml:"type,attr"` // Must be xhtml
|
Type string `xml:"type,attr"` // Must be xhtml
|
||||||
@ -27,8 +21,8 @@ func (x *XHTMLText) Check() error {
|
|||||||
return errors.New("type attribute of xhtml text must be xhtml")
|
return errors.New("type attribute of xhtml text must be xhtml")
|
||||||
}
|
}
|
||||||
|
|
||||||
if x.XHTMLDiv.XMLNS != "http://www.w3.org/1999/xhtml" {
|
if err := x.XHTMLDiv.Check(); err != nil {
|
||||||
return errors.New("xmlns attribute of xhtml text must be http://www.w3.org/1999/xhtml")
|
return fmt.Errorf("xhtml div element %v of xhtml text %v: %v", x.XHTMLDiv, x, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
x
Reference in New Issue
Block a user