diff --git a/node.go b/node.go index d7994d6..e49358c 100644 --- a/node.go +++ b/node.go @@ -54,6 +54,7 @@ type outputConfiguration struct { printSelf bool preserveSpaces bool emptyElementTagSupport bool + skipComments bool } type OutputOption func(*outputConfiguration) @@ -73,6 +74,13 @@ func WithEmptyTagSupport() OutputOption { } } +// WithoutComments will skip comments in output +func WithoutComments() OutputOption { + return func(oc *outputConfiguration) { + oc.skipComments = true + } +} + // InnerText returns the text between the start and end tags of the object. func (n *Node) InnerText() string { var output func(*bytes.Buffer, *Node) @@ -121,9 +129,11 @@ func outputXML(buf *bytes.Buffer, n *Node, preserveSpaces bool, config *outputCo buf.WriteString("]]>") return case CommentNode: - buf.WriteString("") + if !config.skipComments { + buf.WriteString("") + } return case DeclarationNode: buf.WriteString("