From 430f1eb11039227310feb44759762bb72755e9e6 Mon Sep 17 00:00:00 2001 From: kkoehler Date: Fri, 18 Nov 2022 11:55:23 +0100 Subject: [PATCH] added support for skipping comments in result xml --- node.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) 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("