Add XMLEl function
This commit is contained in:
parent
d81de8319f
commit
258100b833
@ -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("</" + name + ">"))
|
||||||
|
return w.err
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// renderChild c to the given writer w if the node type is t.
|
// renderChild c to the given writer w if the node type is t.
|
||||||
func renderChild(w *statefulWriter, c Node, t NodeType) {
|
func renderChild(w *statefulWriter, c Node, t NodeType) {
|
||||||
if w.err != nil || c == nil {
|
if w.err != nil || c == nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user