MCPcopy Create free account
hub / github.com/antchfx/xmlquery / WriteWithOptions

Method WriteWithOptions

node.go:369–394  ·  view source on GitHub ↗

WriteWithOptions writes xml with given options to given writer.

(writer io.Writer, opts ...OutputOption)

Source from the content-addressed store, hash-verified

367
368// WriteWithOptions writes xml with given options to given writer.
369func (n *Node) WriteWithOptions(writer io.Writer, opts ...OutputOption) (err error) {
370 config := &outputConfiguration{
371 preserveSpaces: true,
372 }
373 // Set the options
374 for _, opt := range opts {
375 opt(config)
376 }
377 pastPreserveSpaces := config.preserveSpaces
378 preserveSpaces := calculatePreserveSpaces(n, pastPreserveSpaces)
379 b := bufio.NewWriter(writer)
380 defer b.Flush()
381
382 ident := newIndentation(config.useIndentation, b)
383 if config.printSelf && n.Type != DocumentNode {
384 err = outputXML(b, n, preserveSpaces, config, ident)
385 } else {
386 for n := n.FirstChild; n != nil; n = n.NextSibling {
387 err = outputXML(b, n, preserveSpaces, config, ident)
388 if err != nil {
389 break
390 }
391 }
392 }
393 return
394}
395
396// AddAttr adds a new attribute specified by 'key' and 'val' to a node 'n'.
397// Returns false if the attribute already exists.

Callers 2

OutputXMLWithOptionsMethod · 0.95
WriteMethod · 0.95

Calls 3

calculatePreserveSpacesFunction · 0.85
newIndentationFunction · 0.85
outputXMLFunction · 0.85

Tested by

no test coverage detected