Debian Codegraph @

parsing/xml/xml.go

raw symbols SCIP
1 package xml
2
3 import (
4 "github.com/tomwright/dasel/v3/parsing"
5 )
6
7 const (
8 // XML represents the XML file format.
9 XML parsing.Format = "xml"
10 )
11
12 // xmlChildOrderKey is the metadata key for preserving child element
13 // document order during XML round-trips. Value type: []string.
14 const xmlChildOrderKey = "xml_child_order"
15
16 var _ parsing.Reader = (*xmlReader)(nil)
17 var _ parsing.Writer = (*xmlWriter)(nil)
18
19 func init() {
20 parsing.RegisterReader(XML, newXMLReader)
21 parsing.RegisterWriter(XML, newXMLWriter)
22 }
23
24 type xmlAttr struct {
25 Name string
26 Value string
27 }
28
29 type xmlProcessingInstruction struct {
30 Target string
31 Value string
32 }
33
34 type xmlComment struct {
35 Text string
36 }
37
38 type xmlElement struct {
39 Name string
40 Attrs []xmlAttr
41 Children []*xmlElement
42 Content string
43 ProcessingInstructions []*xmlProcessingInstruction
44 Comments []*xmlComment
45 useChildrenOnly bool
46 compact bool
47 depth int // Tracks nesting depth for proper indentation
48 }
49
50 // appendChild appends child's children (if useChildrenOnly) or the child itself.
51 func (el *xmlElement) appendChild(child *xmlElement) {
52 if child.useChildrenOnly {
53 el.Children = append(el.Children, child.Children...)
54 } else {
55 el.Children = append(el.Children, child)
56 }
57 }