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

Function outputXML

node.go:248–343  ·  view source on GitHub ↗
(w io.Writer, n *Node, preserveSpaces bool, config *outputConfiguration, indent *indentation)

Source from the content-addressed store, hash-verified

246}
247
248func outputXML(w io.Writer, n *Node, preserveSpaces bool, config *outputConfiguration, indent *indentation) (err error) {
249 preserveSpaces = calculatePreserveSpaces(n, preserveSpaces)
250 switch n.Type {
251 case TextNode:
252 _, err = io.WriteString(w, html.EscapeString(n.sanitizedData(preserveSpaces)))
253 return
254 case CharDataNode:
255 _, err = fmt.Fprintf(w, "<![CDATA[%v]]>", n.Data)
256 return
257 case CommentNode:
258 if !config.skipComments {
259 _, err = fmt.Fprintf(w, "<!--%v-->", n.Data)
260 }
261 return
262 case NotationNode:
263 if err = indent.NewLine(); err != nil {
264 return
265 }
266 _, err = fmt.Fprintf(w, "<!%s>", n.Data)
267 return
268 case DeclarationNode:
269 _, err = io.WriteString(w, "<?"+n.Data)
270 if err != nil {
271 return
272 }
273 case ProcessingInstruction:
274 if len(n.ProcInst.Inst) > 0 {
275 _, err = fmt.Fprintf(w, "<?%s %s?>", n.ProcInst.Target, n.ProcInst.Inst)
276 } else {
277 _, err = fmt.Fprintf(w, "<?%s?>", n.ProcInst.Target)
278 }
279 return
280 default:
281 if err = indent.Open(); err != nil {
282 return
283 }
284 if n.Prefix == "" {
285 _, err = io.WriteString(w, "<"+n.Data)
286 } else {
287 _, err = fmt.Fprintf(w, "<%s:%s", n.Prefix, n.Data)
288 }
289 if err != nil {
290 return
291 }
292 }
293
294 for _, attr := range n.Attr {
295 if attr.Name.Space != "" {
296 _, err = fmt.Fprintf(w, ` %s:%s=`, attr.Name.Space, attr.Name.Local)
297 } else {
298 _, err = fmt.Fprintf(w, ` %s=`, attr.Name.Local)
299 }
300 if err != nil {
301 return
302 }
303
304 _, err = fmt.Fprintf(w, `"%v"`, html.EscapeString(attr.Value))
305 if err != nil {

Callers 1

WriteWithOptionsMethod · 0.85

Calls 5

calculatePreserveSpacesFunction · 0.85
sanitizedDataMethod · 0.80
NewLineMethod · 0.80
OpenMethod · 0.80
CloseMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…