diff --git a/gomponents.go b/gomponents.go index 7b73a3b..4ccdae8 100644 --- a/gomponents.go +++ b/gomponents.go @@ -92,6 +92,30 @@ func El(name string, children ...Node) Node { }) } +// XMLEl behaves identically to El with the exception that checking for void +// elements is disabled. This allows use of elements such as "link" which need +// to have children in RSS feeds, for example. +func XMLEl(name string, children ...Node) Node { + return NodeFunc(func(w2 io.Writer) error { + w := &statefulWriter{w: w2} + + w.Write([]byte("<" + name)) + + for _, c := range children { + renderChild(w, c, AttributeType) + } + + w.Write([]byte(">")) + + for _, c := range children { + renderChild(w, c, ElementType) + } + + w.Write([]byte("")) + return w.err + }) +} + // renderChild c to the given writer w if the node type is t. func renderChild(w *statefulWriter, c Node, t NodeType) { if w.err != nil || c == nil {