Debian Codegraph @

etree.go

raw symbols SCIP
1 // Copyright 2015-2019 Brett Vickers.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 // Package etree provides XML services through an Element Tree
6 // abstraction.
7 package etreescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/
8
9 import (
10 "bufioscip-go gomod github.com/golang/go/src go1.23.0 bufio/"
11 "bytesscip-go gomod github.com/golang/go/src go1.23.0 bytes/"
12 "encoding/xmlscip-go gomod github.com/golang/go/src go1.23.0 `encoding/xml`/"
13 "errorsscip-go gomod github.com/golang/go/src go1.23.0 errors/"
14 "ioscip-go gomod github.com/golang/go/src go1.23.0 io/"
15 "iterscip-go gomod github.com/golang/go/src go1.23.0 iter/"
16 "mapsscip-go gomod github.com/golang/go/src go1.23.0 maps/"
17 "osscip-go gomod github.com/golang/go/src go1.23.0 os/"
18 "slicesscip-go gomod github.com/golang/go/src go1.23.0 slices/"
19 "stringsscip-go gomod github.com/golang/go/src go1.23.0 strings/"
20 )
21
22 const (
23 // NoIndent is used with the IndentSettings record to remove all
24 // indenting.
25 NoIndentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/NoIndent. = -1
26 )
27
28 // ErrXML is returned when XML parsing fails due to incorrect formatting.
29 var ErrXMLscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/ErrXML. = errorsscip-go gomod github.com/golang/go/src go1.23.0 errors/.Newscip-go gomod github.com/golang/go/src go1.23.0 errors/New().("etree: invalid XML format")
30
31 // ErrMaxDepth is returned when the depth of the XML tree being read exceeds
32 // the maximum depth allowed by ReadSettings.MaxDepth.
33 var ErrMaxDepthscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/ErrMaxDepth. = errorsscip-go gomod github.com/golang/go/src go1.23.0 errors/.Newscip-go gomod github.com/golang/go/src go1.23.0 errors/New().("etree: XML tree exceeds maximum depth")
34
35 // cdataPrefix is used to detect CDATA text when ReadSettings.PreserveCData is
36 // true.
37 var cdataPrefixscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/cdataPrefix. = []byte("<![CDATA[")
38
39 // ReadSettings determine the default behavior of the Document's ReadFrom*
40 // functions.
41 type ReadSettingsscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/ReadSettings# struct {
42 // CharsetReader, if non-nil, defines a function to generate
43 // charset-conversion readers, converting from the provided non-UTF-8
44 // charset into UTF-8. If nil, the ReadFrom* functions will use a
45 // "pass-through" CharsetReader that performs no conversion on the reader's
46 // data regardless of the value of the "charset" encoding string. Default:
47 // nil.
48 CharsetReaderscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/ReadSettings#CharsetReader. func(charset string, input ioscip-go gomod github.com/golang/go/src go1.23.0 io/.Readerscip-go gomod github.com/golang/go/src go1.23.0 io/Reader#) (ioscip-go gomod github.com/golang/go/src go1.23.0 io/.Readerscip-go gomod github.com/golang/go/src go1.23.0 io/Reader#, error)
49
50 // Permissive allows input containing common mistakes such as missing tags
51 // or attribute values. Default: false.
52 Permissivescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/ReadSettings#Permissive. bool
53
54 // Preserve CDATA character data blocks when decoding XML (instead of
55 // converting it to normal character text). This entails additional
56 // processing and memory usage during ReadFrom* operations. Default:
57 // false.
58 PreserveCDatascip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/ReadSettings#PreserveCData. bool
59
60 // When an element has two or more attributes with the same name,
61 // preserve them instead of keeping only one. Default: false.
62 PreserveDuplicateAttrsscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/ReadSettings#PreserveDuplicateAttrs. bool
63
64 // ValidateInput forces all ReadFrom* functions to validate that the
65 // provided input is composed of "well-formed"(*) XML before processing it.
66 // If invalid XML is detected, the ReadFrom* functions return an error.
67 // Because this option requires the input to be processed twice, it incurs a
68 // significant performance penalty. Default: false.
69 //
70 // (*) Note that this definition of "well-formed" is in the context of the
71 // go standard library's encoding/xml package. Go's encoding/xml package
72 // does not, in fact, guarantee well-formed XML as specified by the W3C XML
73 // recommendation. See: https://github.com/golang/go/issues/68299
74 ValidateInputscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/ReadSettings#ValidateInput. bool
75
76 // Entity to be passed to standard xml.Decoder. Default: nil.
77 Entityscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/ReadSettings#Entity. map[string]string
78
79 // When Permissive is true, AutoClose indicates a set of elements to
80 // consider closed immediately after they are opened, regardless of
81 // whether an end element is present. Commonly set to xml.HTMLAutoClose.
82 // Default: nil.
83 AutoClosescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/ReadSettings#AutoClose. []string
84
85 // MaxDepth is the maximum depth of the XML tree to parse. If the depth of
86 // the XML tree exceeds this value, all ReadFrom* functions return the
87 // error ErrMaxDepth. If MaxDepth is zero or negative, a depth limit of
88 // 1024 is used. Default: 0 (i.e., a limit of 1024).
89 MaxDepthscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/ReadSettings#MaxDepth. int
90 }
91
92 // defaultMaxDepth is the maximum depth of an XML tree parsed by ReadFrom*
93 // functions when ReadSettings.MaxDepth is not set to a positive value.
94 const defaultMaxDepthscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/defaultMaxDepth. = 1024
95
96 // defaultCharsetReader is used by the xml decoder when the ReadSettings
97 // CharsetReader value is nil. It behaves as a "pass-through", ignoring
98 // the requested charset parameter and skipping conversion altogether.
99 func defaultCharsetReaderscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/defaultCharsetReader().(charset string, input ioscip-go gomod github.com/golang/go/src go1.23.0 io/.Readerscip-go gomod github.com/golang/go/src go1.23.0 io/Reader#) (ioscip-go gomod github.com/golang/go/src go1.23.0 io/.Readerscip-go gomod github.com/golang/go/src go1.23.0 io/Reader#, error) {
100 return input, nil
101 }
102
103 // dup creates a duplicate of the ReadSettings object.
104 func (s *ReadSettingsscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/ReadSettings#) dupscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/ReadSettings#dup().() ReadSettingsscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/ReadSettings# {
105 c := *s
106 c.Entityscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/ReadSettings#Entity. = mapsscip-go gomod github.com/golang/go/src go1.23.0 maps/.Clonescip-go gomod github.com/golang/go/src go1.23.0 maps/Clone().(s.Entityscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/ReadSettings#Entity.)
107 return c
108 }
109
110 // WriteSettings determine the behavior of the Document's WriteTo* functions.
111 type WriteSettingsscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/WriteSettings# struct {
112 // CanonicalEndTags forces the production of XML end tags, even for
113 // elements that have no child elements. Default: false.
114 CanonicalEndTagsscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/WriteSettings#CanonicalEndTags. bool
115
116 // CanonicalText forces the production of XML character references for
117 // text data characters &, <, and >. If false, XML character references
118 // are also produced for " and '. Default: false.
119 CanonicalTextscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/WriteSettings#CanonicalText. bool
120
121 // CanonicalAttrVal forces the production of XML character references for
122 // attribute value characters &, < and ". If false, XML character
123 // references are also produced for > and '. Ignored when AttrSingleQuote
124 // is true. Default: false.
125 CanonicalAttrValscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/WriteSettings#CanonicalAttrVal. bool
126
127 // AttrSingleQuote causes attributes to use single quotes (attr='example')
128 // instead of double quotes (attr = "example") when set to true. Default:
129 // false.
130 AttrSingleQuotescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/WriteSettings#AttrSingleQuote. bool
131
132 // UseCRLF causes the document's Indent* functions to use a carriage return
133 // followed by a linefeed ("\r\n") when outputting a newline. If false,
134 // only a linefeed is used ("\n"). Default: false.
135 //
136 // Deprecated: UseCRLF is deprecated. Use IndentSettings.UseCRLF instead.
137 UseCRLFscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/WriteSettings#UseCRLF. bool
138 }
139
140 // dup creates a duplicate of the WriteSettings object.
141 func (s *WriteSettingsscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/WriteSettings#) dupscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/WriteSettings#dup().() WriteSettingsscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/WriteSettings# {
142 return *s
143 }
144
145 // IndentSettings determine the behavior of the Document's Indent* functions.
146 type IndentSettingsscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/IndentSettings# struct {
147 // Spaces indicates the number of spaces to insert for each level of
148 // indentation. Set to etree.NoIndent to remove all indentation. Ignored
149 // when UseTabs is true. Default: 4.
150 Spacesscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/IndentSettings#Spaces. int
151
152 // UseTabs causes tabs to be used instead of spaces when indenting.
153 // Default: false.
154 UseTabsscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/IndentSettings#UseTabs. bool
155
156 // UseCRLF causes newlines to be written as a carriage return followed by
157 // a linefeed ("\r\n"). If false, only a linefeed character is output
158 // for a newline ("\n"). Default: false.
159 UseCRLFscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/IndentSettings#UseCRLF. bool
160
161 // PreserveLeafWhitespace causes indent functions to preserve whitespace
162 // within XML elements containing only non-CDATA character data. Default:
163 // false.
164 PreserveLeafWhitespacescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/IndentSettings#PreserveLeafWhitespace. bool
165
166 // SuppressTrailingWhitespace suppresses the generation of a trailing
167 // whitespace characters (such as newlines) at the end of the indented
168 // document. Default: false.
169 SuppressTrailingWhitespacescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/IndentSettings#SuppressTrailingWhitespace. bool
170 }
171
172 // NewIndentSettings creates a default IndentSettings record.
173 func NewIndentSettingsscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/NewIndentSettings().() *IndentSettingsscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/IndentSettings# {
174 return &IndentSettingsscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/IndentSettings#{
175 Spacesscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/IndentSettings#Spaces.: 4,
176 UseTabsscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/IndentSettings#UseTabs.: false,
177 UseCRLFscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/IndentSettings#UseCRLF.: false,
178 PreserveLeafWhitespacescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/IndentSettings#PreserveLeafWhitespace.: false,
179 SuppressTrailingWhitespacescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/IndentSettings#SuppressTrailingWhitespace.: false,
180 }
181 }
182
183 type indentFuncscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/indentFunc# func(depth int) string
184
185 func getIndentFuncscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/getIndentFunc().(s *IndentSettingsscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/IndentSettings#) indentFuncscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/indentFunc# {
186 if s.UseTabsscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/IndentSettings#UseTabs. {
187 if s.UseCRLFscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/IndentSettings#UseCRLF. {
188 return func(depth int) string { return indentCRLFscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/indentCRLF().(depth, indentTabsscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/indentTabs.) }
189 } else {
190 return func(depth int) string { return indentLFscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/indentLF().(depth, indentTabsscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/indentTabs.) }
191 }
192 } else {
193 if s.Spacesscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/IndentSettings#Spaces. < 0 {
194 return func(depth int) string { return "" }
195 } else if s.UseCRLFscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/IndentSettings#UseCRLF. {
196 return func(depth int) string { return indentCRLFscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/indentCRLF().(depth*s.Spacesscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/IndentSettings#Spaces., indentSpacesscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/indentSpaces.) }
197 } else {
198 return func(depth int) string { return indentLFscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/indentLF().(depth*s.Spacesscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/IndentSettings#Spaces., indentSpacesscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/indentSpaces.) }
199 }
200 }
201 }
202
203 // Writer is the interface that wraps the Write* functions called by each token
204 // type's WriteTo function.
205 type Writerscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Writer# interface {
206 ioscip-go gomod github.com/golang/go/src go1.23.0 io/.StringWriterscip-go gomod github.com/golang/go/src go1.23.0 io/StringWriter#
207 ioscip-go gomod github.com/golang/go/src go1.23.0 io/.ByteWriterscip-go gomod github.com/golang/go/src go1.23.0 io/ByteWriter#
208 ioscip-go gomod github.com/golang/go/src go1.23.0 io/.Writerscip-go gomod github.com/golang/go/src go1.23.0 io/Writer#
209 }
210
211 // A Token is an interface type used to represent XML elements, character
212 // data, CDATA sections, XML comments, XML directives, and XML processing
213 // instructions.
214 type Tokenscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Token# interface {
215 Parentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Token#Parent.() *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#
216 Indexscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Token#Index.() int
217 WriteToscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Token#WriteTo.(w Writerscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Writer#, s *WriteSettingsscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/WriteSettings#)
218 dupscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Token#dup.(parent *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#) Tokenscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Token#
219 setParentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Token#setParent.(parent *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#)
220 setIndexscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Token#setIndex.(index int)
221 }
222
223 // A Document is a container holding a complete XML tree.
224 //
225 // A document has a single embedded element, which contains zero or more child
226 // tokens, one of which is usually the root element. The embedded element may
227 // include other children such as processing instruction tokens or character
228 // data tokens. The document's embedded element is never directly serialized;
229 // only its children are.
230 //
231 // A document also contains read and write settings, which influence the way
232 // the document is deserialized, serialized, and indented.
233 type Documentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Document# struct {
234 Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Document#Element.
235 ReadSettingsscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Document#ReadSettings. ReadSettingsscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/ReadSettings#
236 WriteSettingsscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Document#WriteSettings. WriteSettingsscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/WriteSettings#
237 }
238
239 // An Element represents an XML element, its attributes, and its child tokens.
240 type Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element# struct {
241 Spacescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Space., Tagscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Tag. string // namespace prefix and tag
242 Attrscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Attr. []Attrscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Attr# // key-value attribute pairs
243 Childscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Child. []Tokenscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Token# // child tokens (elements, comments, etc.)
244 parentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#parent. *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element# // parent element
245 indexscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#index. int // token index in parent's children
246 }
247
248 // An Attr represents a key-value attribute within an XML element.
249 type Attrscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Attr# struct {
250 Spacescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Attr#Space., Keyscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Attr#Key. string // The attribute's namespace prefix and key
251 Valuescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Attr#Value. string // The attribute value string
252 elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Attr#element. *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element# // element containing the attribute
253 }
254
255 // charDataFlags are used with CharData tokens to store additional settings.
256 type charDataFlagsscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/charDataFlags# uint8
257
258 const (
259 // The CharData contains only whitespace.
260 whitespaceFlagscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/whitespaceFlag. charDataFlagsscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/charDataFlags# = 1 << iota
261
262 // The CharData contains a CDATA section.
263 cdataFlagscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/cdataFlag.
264 )
265
266 // CharData may be used to represent simple text data or a CDATA section
267 // within an XML document. The Data property should never be modified
268 // directly; use the SetData function instead.
269 type CharDatascip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/CharData# struct {
270 Datascip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/CharData#Data. string // the simple text or CDATA section content
271 parentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/CharData#parent. *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#
272 indexscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/CharData#index. int
273 flagsscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/CharData#flags. charDataFlagsscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/charDataFlags#
274 }
275
276 // A Comment represents an XML comment.
277 type Commentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Comment# struct {
278 Datascip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Comment#Data. string // the comment's text
279 parentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Comment#parent. *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#
280 indexscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Comment#index. int
281 }
282
283 // A Directive represents an XML directive.
284 type Directivescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Directive# struct {
285 Datascip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Directive#Data. string // the directive string
286 parentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Directive#parent. *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#
287 indexscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Directive#index. int
288 }
289
290 // A ProcInst represents an XML processing instruction.
291 type ProcInstscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/ProcInst# struct {
292 Targetscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/ProcInst#Target. string // the processing instruction target
293 Instscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/ProcInst#Inst. string // the processing instruction value
294 parentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/ProcInst#parent. *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#
295 indexscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/ProcInst#index. int
296 }
297
298 // NewDocument creates an XML document without a root element.
299 func NewDocumentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/NewDocument().() *Documentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Document# {
300 return &Documentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Document#{
301 Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Document#Element.: Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#{Childscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Child.: make([]Tokenscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Token#, 0)},
302 }
303 }
304
305 // NewDocumentWithRoot creates an XML document and sets the element 'e' as its
306 // root element. If the element 'e' is already part of another document, it is
307 // first removed from its existing document.
308 func NewDocumentWithRootscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/NewDocumentWithRoot().(e *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#) *Documentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Document# {
309 d := NewDocumentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/NewDocument().()
310 d.SetRootscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Document#SetRoot().(e)
311 return d
312 }
313
314 // Copy returns a recursive, deep copy of the document.
315 func (d *Documentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Document#) Copyscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Document#Copy().() *Documentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Document# {
316 return &Documentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Document#{
317 Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Document#Element.: *(d.Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Document#Element..dupscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#dup().(nil).(*Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#)),
318 ReadSettingsscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Document#ReadSettings.: d.ReadSettingsscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Document#ReadSettings..dupscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/ReadSettings#dup().(),
319 WriteSettingsscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Document#WriteSettings.: d.WriteSettingsscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Document#WriteSettings..dupscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/WriteSettings#dup().(),
320 }
321 }
322
323 // Root returns the root element of the document. It returns nil if there is
324 // no root element.
325 func (d *Documentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Document#) Rootscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Document#Root().() *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element# {
326 for _, t := range d.Childscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Child. {
327 if c, ok := t.(*Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#); ok {
328 return c
329 }
330 }
331 return nil
332 }
333
334 // SetRoot replaces the document's root element with the element 'e'. If the
335 // document already has a root element when this function is called, then the
336 // existing root element is unbound from the document. If the element 'e' is
337 // part of another document, then it is unbound from the other document.
338 func (d *Documentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Document#) SetRootscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Document#SetRoot().(e *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#) {
339 if e.parentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#parent. != nil {
340 e.parentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#parent..RemoveChildscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#RemoveChild().(e)
341 }
342
343 // If there is already a root element, replace it.
344 p := &d.Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Document#Element.
345 for i, t := range p.Childscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Child. {
346 if _, ok := t.(*Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#); ok {
347 t.setParentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Token#setParent.(nil)
348 t.setIndexscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Token#setIndex.(-1)
349 p.Childscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Child.[i] = e
350 e.setParentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#setParent().(p)
351 e.setIndexscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#setIndex().(i)
352 return
353 }
354 }
355
356 // No existing root element, so add it.
357 p.addChildscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#addChild().(e)
358 }
359
360 // ReadFrom reads XML from the reader 'r' into this document. The function
361 // returns the number of bytes read and any error encountered.
362 func (d *Documentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Document#) ReadFromscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Document#ReadFrom().(r ioscip-go gomod github.com/golang/go/src go1.23.0 io/.Readerscip-go gomod github.com/golang/go/src go1.23.0 io/Reader#) (n int64, err error) {
363 if d.ReadSettingsscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Document#ReadSettings..ValidateInputscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/ReadSettings#ValidateInput. {
364 b, err := ioscip-go gomod github.com/golang/go/src go1.23.0 io/.ReadAllscip-go gomod github.com/golang/go/src go1.23.0 io/ReadAll().(r)
365 if err != nil {
366 return 0, err
367 }
368 if err := validateXMLscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/validateXML().(bytesscip-go gomod github.com/golang/go/src go1.23.0 bytes/.NewReaderscip-go gomod github.com/golang/go/src go1.23.0 bytes/NewReader().(b), d.ReadSettingsscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Document#ReadSettings.); err != nil {
369 return 0, err
370 }
371 r = bytesscip-go gomod github.com/golang/go/src go1.23.0 bytes/.NewReaderscip-go gomod github.com/golang/go/src go1.23.0 bytes/NewReader().(b)
372 }
373 return d.Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Document#Element..readFromscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#readFrom().(r, d.ReadSettingsscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Document#ReadSettings.)
374 }
375
376 // ReadFromFile reads XML from a local file at path 'filepath' into this
377 // document.
378 func (d *Documentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Document#) ReadFromFilescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Document#ReadFromFile().(filepath string) error {
379 f, err := osscip-go gomod github.com/golang/go/src go1.23.0 os/.Openscip-go gomod github.com/golang/go/src go1.23.0 os/Open().(filepath)
380 if err != nil {
381 return err
382 }
383 defer f.Closescip-go gomod github.com/golang/go/src go1.23.0 os/File#Close().()
384
385 _, err = d.ReadFromscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Document#ReadFrom().(f)
386 return err
387 }
388
389 // ReadFromBytes reads XML from the byte slice 'b' into the this document.
390 func (d *Documentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Document#) ReadFromBytesscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Document#ReadFromBytes().(b []byte) error {
391 if d.ReadSettingsscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Document#ReadSettings..ValidateInputscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/ReadSettings#ValidateInput. {
392 if err := validateXMLscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/validateXML().(bytesscip-go gomod github.com/golang/go/src go1.23.0 bytes/.NewReaderscip-go gomod github.com/golang/go/src go1.23.0 bytes/NewReader().(b), d.ReadSettingsscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Document#ReadSettings.); err != nil {
393 return err
394 }
395 }
396 _, err := d.Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Document#Element..readFromscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#readFrom().(bytesscip-go gomod github.com/golang/go/src go1.23.0 bytes/.NewReaderscip-go gomod github.com/golang/go/src go1.23.0 bytes/NewReader().(b), d.ReadSettingsscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Document#ReadSettings.)
397 return err
398 }
399
400 // ReadFromString reads XML from the string 's' into this document.
401 func (d *Documentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Document#) ReadFromStringscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Document#ReadFromString().(s string) error {
402 if d.ReadSettingsscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Document#ReadSettings..ValidateInputscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/ReadSettings#ValidateInput. {
403 if err := validateXMLscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/validateXML().(stringsscip-go gomod github.com/golang/go/src go1.23.0 strings/.NewReaderscip-go gomod github.com/golang/go/src go1.23.0 strings/NewReader().(s), d.ReadSettingsscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Document#ReadSettings.); err != nil {
404 return err
405 }
406 }
407 _, err := d.Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Document#Element..readFromscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#readFrom().(stringsscip-go gomod github.com/golang/go/src go1.23.0 strings/.NewReaderscip-go gomod github.com/golang/go/src go1.23.0 strings/NewReader().(s), d.ReadSettingsscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Document#ReadSettings.)
408 return err
409 }
410
411 // validateXML determines if the data read from the reader 'r' contains
412 // well-formed XML according to the rules set by the go xml package.
413 func validateXMLscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/validateXML().(r ioscip-go gomod github.com/golang/go/src go1.23.0 io/.Readerscip-go gomod github.com/golang/go/src go1.23.0 io/Reader#, settings ReadSettingsscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/ReadSettings#) error {
414 dec := newDecoderscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/newDecoder().(r, settings)
415 err := dec.Decodescip-go gomod github.com/golang/go/src go1.23.0 `encoding/xml`/Decoder#Decode().(new(interface{}))
416 if err != nil {
417 return err
418 }
419
420 // If there are any trailing tokens after unmarshalling with Decode(),
421 // then the XML input didn't terminate properly.
422 _, err = dec.Tokenscip-go gomod github.com/golang/go/src go1.23.0 `encoding/xml`/Decoder#Token().()
423 if err == ioscip-go gomod github.com/golang/go/src go1.23.0 io/.EOFscip-go gomod github.com/golang/go/src go1.23.0 io/EOF. {
424 return nil
425 }
426 return ErrXMLscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/ErrXML.
427 }
428
429 // newDecoder creates an XML decoder for the reader 'r' configured using
430 // the provided read settings.
431 func newDecoderscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/newDecoder().(r ioscip-go gomod github.com/golang/go/src go1.23.0 io/.Readerscip-go gomod github.com/golang/go/src go1.23.0 io/Reader#, settings ReadSettingsscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/ReadSettings#) *xmlscip-go gomod github.com/golang/go/src go1.23.0 `encoding/xml`/.Decoderscip-go gomod github.com/golang/go/src go1.23.0 `encoding/xml`/Decoder# {
432 d := xmlscip-go gomod github.com/golang/go/src go1.23.0 `encoding/xml`/.NewDecoderscip-go gomod github.com/golang/go/src go1.23.0 `encoding/xml`/NewDecoder().(r)
433 d.CharsetReaderscip-go gomod github.com/golang/go/src go1.23.0 `encoding/xml`/Decoder#CharsetReader. = settings.CharsetReaderscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/ReadSettings#CharsetReader.
434 if d.CharsetReaderscip-go gomod github.com/golang/go/src go1.23.0 `encoding/xml`/Decoder#CharsetReader. == nil {
435 d.CharsetReaderscip-go gomod github.com/golang/go/src go1.23.0 `encoding/xml`/Decoder#CharsetReader. = defaultCharsetReaderscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/defaultCharsetReader().
436 }
437 d.Strictscip-go gomod github.com/golang/go/src go1.23.0 `encoding/xml`/Decoder#Strict. = !settings.Permissivescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/ReadSettings#Permissive.
438 d.Entityscip-go gomod github.com/golang/go/src go1.23.0 `encoding/xml`/Decoder#Entity. = settings.Entityscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/ReadSettings#Entity.
439 d.AutoClosescip-go gomod github.com/golang/go/src go1.23.0 `encoding/xml`/Decoder#AutoClose. = settings.AutoClosescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/ReadSettings#AutoClose.
440 return d
441 }
442
443 // WriteTo serializes the document out to the writer 'w'. The function returns
444 // the number of bytes written and any error encountered.
445 func (d *Documentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Document#) WriteToscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Document#WriteTo().(w ioscip-go gomod github.com/golang/go/src go1.23.0 io/.Writerscip-go gomod github.com/golang/go/src go1.23.0 io/Writer#) (n int64, err error) {
446 xw := newXmlWriterscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/newXmlWriter().(w)
447 b := bufioscip-go gomod github.com/golang/go/src go1.23.0 bufio/.NewWriterscip-go gomod github.com/golang/go/src go1.23.0 bufio/NewWriter().(xw)
448 for _, c := range d.Childscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Child. {
449 c.WriteToscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Token#WriteTo.(b, &d.WriteSettingsscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Document#WriteSettings.)
450 }
451 err, n = b.Flushscip-go gomod github.com/golang/go/src go1.23.0 bufio/Writer#Flush().(), xw.bytesscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/xmlWriter#bytes.
452 return
453 }
454
455 // WriteToFile serializes the document out to the file at path 'filepath'.
456 func (d *Documentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Document#) WriteToFilescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Document#WriteToFile().(filepath string) error {
457 f, err := osscip-go gomod github.com/golang/go/src go1.23.0 os/.Createscip-go gomod github.com/golang/go/src go1.23.0 os/Create().(filepath)
458 if err != nil {
459 return err
460 }
461 defer f.Closescip-go gomod github.com/golang/go/src go1.23.0 os/File#Close().()
462 _, err = d.WriteToscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Document#WriteTo().(f)
463 return err
464 }
465
466 // WriteToBytes serializes this document into a slice of bytes.
467 func (d *Documentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Document#) WriteToBytesscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Document#WriteToBytes().() (b []byte, err error) {
468 var buf bytesscip-go gomod github.com/golang/go/src go1.23.0 bytes/.Bufferscip-go gomod github.com/golang/go/src go1.23.0 bytes/Buffer#
469 if _, err = d.WriteToscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Document#WriteTo().(&buf); err != nil {
470 return
471 }
472 return buf.Bytesscip-go gomod github.com/golang/go/src go1.23.0 bytes/Buffer#Bytes().(), nil
473 }
474
475 // WriteToString serializes this document into a string.
476 func (d *Documentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Document#) WriteToStringscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Document#WriteToString().() (s string, err error) {
477 var b []byte
478 if b, err = d.WriteToBytesscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Document#WriteToBytes().(); err != nil {
479 return
480 }
481 return string(b), nil
482 }
483
484 // Indent modifies the document's element tree by inserting character data
485 // tokens containing newlines and spaces for indentation. The amount of
486 // indentation per depth level is given by the 'spaces' parameter. Other than
487 // the number of spaces, default IndentSettings are used.
488 func (d *Documentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Document#) Indentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Document#Indent().(spaces int) {
489 s := NewIndentSettingsscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/NewIndentSettings().()
490 s.Spacesscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/IndentSettings#Spaces. = spaces
491 d.IndentWithSettingsscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Document#IndentWithSettings().(s)
492 }
493
494 // IndentTabs modifies the document's element tree by inserting CharData
495 // tokens containing newlines and tabs for indentation. One tab is used per
496 // indentation level. Other than the use of tabs, default IndentSettings
497 // are used.
498 func (d *Documentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Document#) IndentTabsscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Document#IndentTabs().() {
499 s := NewIndentSettingsscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/NewIndentSettings().()
500 s.UseTabsscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/IndentSettings#UseTabs. = true
501 d.IndentWithSettingsscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Document#IndentWithSettings().(s)
502 }
503
504 // IndentWithSettings modifies the document's element tree by inserting
505 // character data tokens containing newlines and indentation. The behavior
506 // of the indentation algorithm is configured by the indent settings.
507 func (d *Documentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Document#) IndentWithSettingsscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Document#IndentWithSettings().(s *IndentSettingsscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/IndentSettings#) {
508 // WriteSettings.UseCRLF is deprecated. Until removed from the package, it
509 // overrides IndentSettings.UseCRLF when true.
510 if d.WriteSettingsscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Document#WriteSettings..UseCRLFscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/WriteSettings#UseCRLF. {
511 s.UseCRLFscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/IndentSettings#UseCRLF. = true
512 }
513
514 d.Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Document#Element..indentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#indent().(0, getIndentFuncscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/getIndentFunc().(s), s)
515
516 if s.SuppressTrailingWhitespacescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/IndentSettings#SuppressTrailingWhitespace. {
517 d.Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Document#Element..stripTrailingWhitespacescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#stripTrailingWhitespace().()
518 }
519 }
520
521 // Unindent modifies the document's element tree by removing character data
522 // tokens containing only whitespace. Other than the removal of indentation,
523 // default IndentSettings are used.
524 func (d *Documentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Document#) Unindentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Document#Unindent().() {
525 s := NewIndentSettingsscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/NewIndentSettings().()
526 s.Spacesscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/IndentSettings#Spaces. = NoIndentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/NoIndent.
527 d.IndentWithSettingsscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Document#IndentWithSettings().(s)
528 }
529
530 // NewElement creates an unparented element with the specified tag (i.e.,
531 // name). The tag may include a namespace prefix followed by a colon.
532 func NewElementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/NewElement().(tag string) *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element# {
533 space, stag := spaceDecomposescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/spaceDecompose().(tag)
534 return newElementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/newElement().(space, stag, nil)
535 }
536
537 // newElement is a helper function that creates an element and binds it to
538 // a parent element if possible.
539 func newElementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/newElement().(space, tag string, parent *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#) *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element# {
540 e := &Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#{
541 Spacescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Space.: space,
542 Tagscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Tag.: tag,
543 Attrscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Attr.: make([]Attrscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Attr#, 0),
544 Childscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Child.: make([]Tokenscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Token#, 0),
545 parentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#parent.: parent,
546 indexscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#index.: -1,
547 }
548 if parent != nil {
549 parent.addChildscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#addChild().(e)
550 }
551 return e
552 }
553
554 // Copy creates a recursive, deep copy of the element and all its attributes
555 // and children. The returned element has no parent but can be parented to a
556 // another element using AddChild, or added to a document with SetRoot or
557 // NewDocumentWithRoot.
558 func (e *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#) Copyscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Copy().() *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element# {
559 return e.dupscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#dup().(nil).(*Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#)
560 }
561
562 // FullTag returns the element e's complete tag, including namespace prefix if
563 // present.
564 func (e *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#) FullTagscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#FullTag().() string {
565 if e.Spacescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Space. == "" {
566 return e.Tagscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Tag.
567 }
568 return e.Spacescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Space. + ":" + e.Tagscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Tag.
569 }
570
571 // NamespaceURI returns the XML namespace URI associated with the element. If
572 // the element is part of the XML default namespace, NamespaceURI returns the
573 // empty string.
574 func (e *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#) NamespaceURIscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#NamespaceURI().() string {
575 if e.Spacescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Space. == "" {
576 return e.findDefaultNamespaceURIscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#findDefaultNamespaceURI().()
577 }
578 return e.findLocalNamespaceURIscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#findLocalNamespaceURI().(e.Spacescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Space.)
579 }
580
581 // findLocalNamespaceURI finds the namespace URI corresponding to the
582 // requested prefix.
583 func (e *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#) findLocalNamespaceURIscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#findLocalNamespaceURI().(prefix string) string {
584 for _, a := range e.Attrscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Attr. {
585 if a.Spacescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Attr#Space. == "xmlns" && a.Keyscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Attr#Key. == prefix {
586 return a.Valuescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Attr#Value.
587 }
588 }
589
590 if e.parentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#parent. == nil {
591 return ""
592 }
593
594 return e.parentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#parent..findLocalNamespaceURIscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#findLocalNamespaceURI().(prefix)
595 }
596
597 // findDefaultNamespaceURI finds the default namespace URI of the element.
598 func (e *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#) findDefaultNamespaceURIscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#findDefaultNamespaceURI().() string {
599 for _, a := range e.Attrscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Attr. {
600 if a.Spacescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Attr#Space. == "" && a.Keyscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Attr#Key. == "xmlns" {
601 return a.Valuescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Attr#Value.
602 }
603 }
604
605 if e.parentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#parent. == nil {
606 return ""
607 }
608
609 return e.parentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#parent..findDefaultNamespaceURIscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#findDefaultNamespaceURI().()
610 }
611
612 // namespacePrefix returns the namespace prefix associated with the element.
613 func (e *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#) namespacePrefixscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#namespacePrefix().() string {
614 return e.Spacescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Space.
615 }
616
617 // name returns the tag associated with the element.
618 func (e *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#) namescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#name().() string {
619 return e.Tagscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Tag.
620 }
621
622 // ReindexChildren recalculates the index values of the element's child
623 // tokens. This is necessary only if you have manually manipulated the
624 // element's `Child` array.
625 func (e *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#) ReindexChildrenscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#ReindexChildren().() {
626 for i := 0; i < len(e.Childscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Child.); i++ {
627 e.Childscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Child.[i].setIndexscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Token#setIndex.(i)
628 }
629 }
630
631 // Text returns all character data immediately following the element's opening
632 // tag.
633 func (e *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#) Textscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Text().() string {
634 if len(e.Childscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Child.) == 0 {
635 return ""
636 }
637
638 var text string
639 var b stringsscip-go gomod github.com/golang/go/src go1.23.0 strings/.Builderscip-go gomod github.com/golang/go/src go1.23.0 strings/Builder#
640 for _, ch := range e.Childscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Child. {
641 if cd, ok := ch.(*CharDatascip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/CharData#); ok {
642 if text == "" {
643 text = cd.Datascip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/CharData#Data.
644 } else {
645 if b.Lenscip-go gomod github.com/golang/go/src go1.23.0 strings/Builder#Len().() == 0 {
646 b.WriteStringscip-go gomod github.com/golang/go/src go1.23.0 strings/Builder#WriteString().(text)
647 }
648 b.WriteStringscip-go gomod github.com/golang/go/src go1.23.0 strings/Builder#WriteString().(cd.Datascip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/CharData#Data.)
649 }
650 } else if _, ok := ch.(*Commentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Comment#); ok {
651 // ignore
652 } else {
653 break
654 }
655 }
656
657 if b.Lenscip-go gomod github.com/golang/go/src go1.23.0 strings/Builder#Len().() > 0 {
658 return b.Stringscip-go gomod github.com/golang/go/src go1.23.0 strings/Builder#String().()
659 }
660 return text
661 }
662
663 // SetText replaces all character data immediately following an element's
664 // opening tag with the requested string.
665 func (e *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#) SetTextscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#SetText().(text string) {
666 e.replaceTextscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#replaceText().(0, text, 0)
667 }
668
669 // SetCData replaces all character data immediately following an element's
670 // opening tag with a CDATA section.
671 func (e *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#) SetCDatascip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#SetCData().(text string) {
672 e.replaceTextscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#replaceText().(0, text, cdataFlagscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/cdataFlag.)
673 }
674
675 // Tail returns all character data immediately following the element's end
676 // tag.
677 func (e *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#) Tailscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Tail().() string {
678 if e.Parentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Parent().() == nil {
679 return ""
680 }
681
682 p := e.Parentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Parent().()
683 i := e.Indexscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Index().()
684
685 var text string
686 var b stringsscip-go gomod github.com/golang/go/src go1.23.0 strings/.Builderscip-go gomod github.com/golang/go/src go1.23.0 strings/Builder#
687 for _, ch := range p.Childscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Child.[i+1:] {
688 if cd, ok := ch.(*CharDatascip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/CharData#); ok {
689 if text == "" {
690 text = cd.Datascip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/CharData#Data.
691 } else {
692 if b.Lenscip-go gomod github.com/golang/go/src go1.23.0 strings/Builder#Len().() == 0 {
693 b.WriteStringscip-go gomod github.com/golang/go/src go1.23.0 strings/Builder#WriteString().(text)
694 }
695 b.WriteStringscip-go gomod github.com/golang/go/src go1.23.0 strings/Builder#WriteString().(cd.Datascip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/CharData#Data.)
696 }
697 } else {
698 break
699 }
700 }
701
702 if b.Lenscip-go gomod github.com/golang/go/src go1.23.0 strings/Builder#Len().() > 0 {
703 return b.Stringscip-go gomod github.com/golang/go/src go1.23.0 strings/Builder#String().()
704 }
705 return text
706 }
707
708 // SetTail replaces all character data immediately following the element's end
709 // tag with the requested string.
710 func (e *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#) SetTailscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#SetTail().(text string) {
711 if e.Parentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Parent().() == nil {
712 return
713 }
714
715 p := e.Parentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Parent().()
716 p.replaceTextscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#replaceText().(e.Indexscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Index().()+1, text, 0)
717 }
718
719 // replaceText is a helper function that replaces a series of chardata tokens
720 // starting at index i with the requested text.
721 func (e *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#) replaceTextscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#replaceText().(i int, text string, flags charDataFlagsscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/charDataFlags#) {
722 end := e.findTermCharDataIndexscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#findTermCharDataIndex().(i)
723
724 switch {
725 case end == i:
726 if text != "" {
727 // insert a new chardata token at index i
728 cd := newCharDatascip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/newCharData().(text, flags, nil)
729 e.InsertChildAtscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#InsertChildAt().(i, cd)
730 }
731
732 case end == i+1:
733 if text == "" {
734 // remove the chardata token at index i
735 e.RemoveChildAtscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#RemoveChildAt().(i)
736 } else {
737 // replace the first and only character token at index i
738 cd := e.Childscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Child.[i].(*CharDatascip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/CharData#)
739 cd.Datascip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/CharData#Data., cd.flagsscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/CharData#flags. = text, flags
740 }
741
742 default:
743 if text == "" {
744 // remove all chardata tokens starting from index i
745 copy(e.Childscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Child.[i:], e.Childscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Child.[end:])
746 removed := end - i
747 e.Childscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Child. = e.Childscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Child.[:len(e.Childscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Child.)-removed]
748 for j := i; j < len(e.Childscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Child.); j++ {
749 e.Childscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Child.[j].setIndexscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Token#setIndex.(j)
750 }
751 } else {
752 // replace the first chardata token at index i and remove all
753 // subsequent chardata tokens
754 cd := e.Childscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Child.[i].(*CharDatascip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/CharData#)
755 cd.Datascip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/CharData#Data., cd.flagsscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/CharData#flags. = text, flags
756 copy(e.Childscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Child.[i+1:], e.Childscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Child.[end:])
757 removed := end - (i + 1)
758 e.Childscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Child. = e.Childscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Child.[:len(e.Childscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Child.)-removed]
759 for j := i + 1; j < len(e.Childscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Child.); j++ {
760 e.Childscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Child.[j].setIndexscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Token#setIndex.(j)
761 }
762 }
763 }
764 }
765
766 // findTermCharDataIndex finds the index of the first child token that isn't
767 // a CharData token. It starts from the requested start index.
768 func (e *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#) findTermCharDataIndexscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#findTermCharDataIndex().(start int) int {
769 for i := start; i < len(e.Childscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Child.); i++ {
770 if _, ok := e.Childscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Child.[i].(*CharDatascip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/CharData#); !ok {
771 return i
772 }
773 }
774 return len(e.Childscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Child.)
775 }
776
777 // CreateElement creates a new element with the specified tag (i.e., name) and
778 // adds it as the last child of element 'e'. The tag may include a prefix
779 // followed by a colon.
780 func (e *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#) CreateElementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#CreateElement().(tag string) *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element# {
781 space, stag := spaceDecomposescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/spaceDecompose().(tag)
782 return newElementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/newElement().(space, stag, e)
783 }
784
785 // CreateChild performs the same task as CreateElement but calls a
786 // continuation function after the child element is created, allowing
787 // additional actions to be performed on the child element before returning.
788 //
789 // This method of element creation is particularly useful when building nested
790 // XML documents from code. For example:
791 //
792 // org := doc.CreateChild("organization", func(e *Element) {
793 // e.CreateComment("Mary")
794 // e.CreateChild("person", func(e *Element) {
795 // e.CreateAttr("name", "Mary")
796 // e.CreateAttr("age", "30")
797 // e.CreateAttr("hair", "brown")
798 // })
799 // })
800 func (e *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#) CreateChildscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#CreateChild().(tag string, cont func(e *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#)) *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element# {
801 child := e.CreateElementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#CreateElement().(tag)
802 cont(child)
803 return child
804 }
805
806 // AddChild adds the token 't' as the last child of the element. If token 't'
807 // was already the child of another element, it is first removed from its
808 // parent element.
809 func (e *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#) AddChildscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#AddChild().(t Tokenscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Token#) {
810 if t.Parentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Token#Parent.() != nil {
811 t.Parentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Token#Parent.().RemoveChildscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#RemoveChild().(t)
812 }
813 e.addChildscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#addChild().(t)
814 }
815
816 // InsertChild inserts the token 't' into this element's list of children just
817 // before the element's existing child token 'ex'. If the existing element
818 // 'ex' does not appear in this element's list of child tokens, then 't' is
819 // added to the end of this element's list of child tokens. If token 't' is
820 // already the child of another element, it is first removed from the other
821 // element's list of child tokens.
822 //
823 // Deprecated: InsertChild is deprecated. Use InsertChildAt instead.
824 func (e *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#) InsertChildscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#InsertChild().(ex Tokenscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Token#, t Tokenscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Token#) {
825 if ex == nil || ex.Parentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Token#Parent.() != e {
826 e.AddChildscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#AddChild().(t)
827 return
828 }
829
830 if t.Parentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Token#Parent.() != nil {
831 t.Parentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Token#Parent.().RemoveChildscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#RemoveChild().(t)
832 }
833
834 t.setParentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Token#setParent.(e)
835
836 i := ex.Indexscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Token#Index.()
837 e.Childscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Child. = append(e.Childscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Child., nil)
838 copy(e.Childscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Child.[i+1:], e.Childscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Child.[i:])
839 e.Childscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Child.[i] = t
840
841 for j := i; j < len(e.Childscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Child.); j++ {
842 e.Childscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Child.[j].setIndexscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Token#setIndex.(j)
843 }
844 }
845
846 // InsertChildAt inserts the token 't' into this element's list of child
847 // tokens just before the requested 'index'. If the index is greater than or
848 // equal to the length of the list of child tokens, then the token 't' is
849 // added to the end of the list of child tokens.
850 func (e *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#) InsertChildAtscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#InsertChildAt().(index int, t Tokenscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Token#) {
851 if index >= len(e.Childscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Child.) {
852 e.AddChildscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#AddChild().(t)
853 return
854 }
855
856 if t.Parentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Token#Parent.() != nil {
857 if t.Parentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Token#Parent.() == e && t.Indexscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Token#Index.() < index {
858 index--
859 }
860 t.Parentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Token#Parent.().RemoveChildscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#RemoveChild().(t)
861 }
862
863 t.setParentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Token#setParent.(e)
864
865 e.Childscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Child. = append(e.Childscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Child., nil)
866 copy(e.Childscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Child.[index+1:], e.Childscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Child.[index:])
867 e.Childscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Child.[index] = t
868
869 for j := index; j < len(e.Childscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Child.); j++ {
870 e.Childscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Child.[j].setIndexscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Token#setIndex.(j)
871 }
872 }
873
874 // RemoveChild attempts to remove the token 't' from this element's list of
875 // child tokens. If the token 't' was a child of this element, then it is
876 // removed and returned. Otherwise, nil is returned.
877 func (e *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#) RemoveChildscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#RemoveChild().(t Tokenscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Token#) Tokenscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Token# {
878 if t.Parentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Token#Parent.() != e {
879 return nil
880 }
881 return e.RemoveChildAtscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#RemoveChildAt().(t.Indexscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Token#Index.())
882 }
883
884 // RemoveChildAt removes the child token appearing in slot 'index' of this
885 // element's list of child tokens. The removed child token is then returned.
886 // If the index is out of bounds, no child is removed and nil is returned.
887 func (e *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#) RemoveChildAtscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#RemoveChildAt().(index int) Tokenscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Token# {
888 if index >= len(e.Childscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Child.) {
889 return nil
890 }
891
892 t := e.Childscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Child.[index]
893 for j := index + 1; j < len(e.Childscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Child.); j++ {
894 e.Childscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Child.[j].setIndexscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Token#setIndex.(j - 1)
895 }
896 e.Childscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Child. = append(e.Childscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Child.[:index], e.Childscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Child.[index+1:]...)
897 t.setIndexscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Token#setIndex.(-1)
898 t.setParentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Token#setParent.(nil)
899 return t
900 }
901
902 // autoClose analyzes the stack's top element and the current token to decide
903 // whether the top element should be closed.
904 func (e *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#) autoClosescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#autoClose().(stack *stackscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/stack#[*Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#], t xmlscip-go gomod github.com/golang/go/src go1.23.0 `encoding/xml`/.Tokenscip-go gomod github.com/golang/go/src go1.23.0 `encoding/xml`/Token#, tags []string) {
905 if stack.emptyscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/stack#empty().() {
906 return
907 }
908
909 top := stack.peekscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/stack#peek().()
910
911 for _, tag := range tags {
912 if stringsscip-go gomod github.com/golang/go/src go1.23.0 strings/.EqualFoldscip-go gomod github.com/golang/go/src go1.23.0 strings/EqualFold().(tag, top.FullTagscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#FullTag().()) {
913 if e, ok := t.(xmlscip-go gomod github.com/golang/go/src go1.23.0 `encoding/xml`/.EndElementscip-go gomod github.com/golang/go/src go1.23.0 `encoding/xml`/EndElement#); !ok ||
914 !stringsscip-go gomod github.com/golang/go/src go1.23.0 strings/.EqualFoldscip-go gomod github.com/golang/go/src go1.23.0 strings/EqualFold().(e.Namescip-go gomod github.com/golang/go/src go1.23.0 `encoding/xml`/EndElement#Name..Spacescip-go gomod github.com/golang/go/src go1.23.0 `encoding/xml`/Name#Space., top.Spacescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Space.) ||
915 !stringsscip-go gomod github.com/golang/go/src go1.23.0 strings/.EqualFoldscip-go gomod github.com/golang/go/src go1.23.0 strings/EqualFold().(e.Namescip-go gomod github.com/golang/go/src go1.23.0 `encoding/xml`/EndElement#Name..Localscip-go gomod github.com/golang/go/src go1.23.0 `encoding/xml`/Name#Local., top.Tagscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Tag.) {
916 stack.popscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/stack#pop().()
917 }
918 break
919 }
920 }
921 }
922
923 // ReadFrom reads XML from the reader 'ri' and stores the result as a new
924 // child of this element.
925 func (e *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#) readFromscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#readFrom().(ri ioscip-go gomod github.com/golang/go/src go1.23.0 io/.Readerscip-go gomod github.com/golang/go/src go1.23.0 io/Reader#, settings ReadSettingsscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/ReadSettings#) (n int64, err error) {
926 var r xmlReaderscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/xmlReader#
927 var pr *xmlPeekReaderscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/xmlPeekReader#
928 if settings.PreserveCDatascip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/ReadSettings#PreserveCData. {
929 pr = newXmlPeekReaderscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/newXmlPeekReader().(ri)
930 r = pr
931 } else {
932 r = newXmlSimpleReaderscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/newXmlSimpleReader().(ri)
933 }
934
935 attrCheck := make(map[xmlscip-go gomod github.com/golang/go/src go1.23.0 `encoding/xml`/.Namescip-go gomod github.com/golang/go/src go1.23.0 `encoding/xml`/Name#]int)
936 dec := newDecoderscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/newDecoder().(r, settings)
937
938 maxDepth := settings.MaxDepthscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/ReadSettings#MaxDepth.
939 if maxDepth <= 0 {
940 maxDepth = defaultMaxDepthscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/defaultMaxDepth.
941 }
942
943 var stack stackscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/stack#[*Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#]
944 stack.pushscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/stack#push().(e)
945 for {
946 if pr != nil {
947 pr.PeekPreparescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/xmlPeekReader#PeekPrepare().(dec.InputOffsetscip-go gomod github.com/golang/go/src go1.23.0 `encoding/xml`/Decoder#InputOffset().(), len(cdataPrefixscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/cdataPrefix.))
948 }
949
950 t, err := dec.RawTokenscip-go gomod github.com/golang/go/src go1.23.0 `encoding/xml`/Decoder#RawToken().()
951
952 if settings.Permissivescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/ReadSettings#Permissive. && settings.AutoClosescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/ReadSettings#AutoClose. != nil {
953 e.autoClosescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#autoClose().(&stack, t, settings.AutoClosescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/ReadSettings#AutoClose.)
954 }
955
956 switch {
957 case err == ioscip-go gomod github.com/golang/go/src go1.23.0 io/.EOFscip-go gomod github.com/golang/go/src go1.23.0 io/EOF.:
958 if len(stack.datascip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/stack#data.) != 1 {
959 return r.Bytesscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/xmlReader#Bytes.(), ErrXMLscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/ErrXML.
960 }
961 return r.Bytesscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/xmlReader#Bytes.(), nil
962 case err != nil:
963 return r.Bytesscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/xmlReader#Bytes.(), err
964 case stack.emptyscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/stack#empty().():
965 return r.Bytesscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/xmlReader#Bytes.(), ErrXMLscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/ErrXML.
966 }
967
968 top := stack.peekscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/stack#peek().()
969
970 switch t := t.(type) {
971 case xmlscip-go gomod github.com/golang/go/src go1.23.0 `encoding/xml`/.StartElementscip-go gomod github.com/golang/go/src go1.23.0 `encoding/xml`/StartElement#:
972 if len(stack.datascip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/stack#data.) > maxDepth {
973 return r.Bytesscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/xmlReader#Bytes.(), ErrMaxDepthscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/ErrMaxDepth.
974 }
975 e := newElementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/newElement().(t.Namescip-go gomod github.com/golang/go/src go1.23.0 `encoding/xml`/StartElement#Name..Spacescip-go gomod github.com/golang/go/src go1.23.0 `encoding/xml`/Name#Space., t.Namescip-go gomod github.com/golang/go/src go1.23.0 `encoding/xml`/StartElement#Name..Localscip-go gomod github.com/golang/go/src go1.23.0 `encoding/xml`/Name#Local., top)
976 if settings.PreserveDuplicateAttrsscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/ReadSettings#PreserveDuplicateAttrs. || len(t.Attrscip-go gomod github.com/golang/go/src go1.23.0 `encoding/xml`/StartElement#Attr.) < 2 {
977 for _, a := range t.Attrscip-go gomod github.com/golang/go/src go1.23.0 `encoding/xml`/StartElement#Attr. {
978 e.addAttrscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#addAttr().(a.Namescip-go gomod github.com/golang/go/src go1.23.0 `encoding/xml`/Attr#Name..Spacescip-go gomod github.com/golang/go/src go1.23.0 `encoding/xml`/Name#Space., a.Namescip-go gomod github.com/golang/go/src go1.23.0 `encoding/xml`/Attr#Name..Localscip-go gomod github.com/golang/go/src go1.23.0 `encoding/xml`/Name#Local., a.Valuescip-go gomod github.com/golang/go/src go1.23.0 `encoding/xml`/Attr#Value.)
979 }
980 } else {
981 for _, a := range t.Attrscip-go gomod github.com/golang/go/src go1.23.0 `encoding/xml`/StartElement#Attr. {
982 if i, contains := attrCheck[a.Namescip-go gomod github.com/golang/go/src go1.23.0 `encoding/xml`/Attr#Name.]; contains {
983 e.Attrscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Attr.[i].Valuescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Attr#Value. = a.Valuescip-go gomod github.com/golang/go/src go1.23.0 `encoding/xml`/Attr#Value.
984 } else {
985 attrCheck[a.Namescip-go gomod github.com/golang/go/src go1.23.0 `encoding/xml`/Attr#Name.] = e.addAttrscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#addAttr().(a.Namescip-go gomod github.com/golang/go/src go1.23.0 `encoding/xml`/Attr#Name..Spacescip-go gomod github.com/golang/go/src go1.23.0 `encoding/xml`/Name#Space., a.Namescip-go gomod github.com/golang/go/src go1.23.0 `encoding/xml`/Attr#Name..Localscip-go gomod github.com/golang/go/src go1.23.0 `encoding/xml`/Name#Local., a.Valuescip-go gomod github.com/golang/go/src go1.23.0 `encoding/xml`/Attr#Value.)
986 }
987 }
988 clear(attrCheck)
989 }
990 stack.pushscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/stack#push().(e)
991 case xmlscip-go gomod github.com/golang/go/src go1.23.0 `encoding/xml`/.EndElementscip-go gomod github.com/golang/go/src go1.23.0 `encoding/xml`/EndElement#:
992 if top.Tagscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Tag. != t.Namescip-go gomod github.com/golang/go/src go1.23.0 `encoding/xml`/EndElement#Name..Localscip-go gomod github.com/golang/go/src go1.23.0 `encoding/xml`/Name#Local. || top.Spacescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Space. != t.Namescip-go gomod github.com/golang/go/src go1.23.0 `encoding/xml`/EndElement#Name..Spacescip-go gomod github.com/golang/go/src go1.23.0 `encoding/xml`/Name#Space. {
993 return r.Bytesscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/xmlReader#Bytes.(), ErrXMLscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/ErrXML.
994 }
995 stack.popscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/stack#pop().()
996 case xmlscip-go gomod github.com/golang/go/src go1.23.0 `encoding/xml`/.CharDatascip-go gomod github.com/golang/go/src go1.23.0 `encoding/xml`/CharData#:
997 data := string(t)
998 var flags charDataFlagsscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/charDataFlags#
999 if pr != nil {
1000 peekBuf := pr.PeekFinalizescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/xmlPeekReader#PeekFinalize().()
1001 if bytesscip-go gomod github.com/golang/go/src go1.23.0 bytes/.Equalscip-go gomod github.com/golang/go/src go1.23.0 bytes/Equal().(peekBuf, cdataPrefixscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/cdataPrefix.) {
1002 flags = cdataFlagscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/cdataFlag.
1003 } else if isWhitespacescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/isWhitespace().(data) {
1004 flags = whitespaceFlagscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/whitespaceFlag.
1005 }
1006 } else {
1007 if isWhitespacescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/isWhitespace().(data) {
1008 flags = whitespaceFlagscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/whitespaceFlag.
1009 }
1010 }
1011 newCharDatascip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/newCharData().(data, flags, top)
1012 case xmlscip-go gomod github.com/golang/go/src go1.23.0 `encoding/xml`/.Commentscip-go gomod github.com/golang/go/src go1.23.0 `encoding/xml`/Comment#:
1013 newCommentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/newComment().(string(t), top)
1014 case xmlscip-go gomod github.com/golang/go/src go1.23.0 `encoding/xml`/.Directivescip-go gomod github.com/golang/go/src go1.23.0 `encoding/xml`/Directive#:
1015 newDirectivescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/newDirective().(string(t), top)
1016 case xmlscip-go gomod github.com/golang/go/src go1.23.0 `encoding/xml`/.ProcInstscip-go gomod github.com/golang/go/src go1.23.0 `encoding/xml`/ProcInst#:
1017 newProcInstscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/newProcInst().(t.Targetscip-go gomod github.com/golang/go/src go1.23.0 `encoding/xml`/ProcInst#Target., string(t.Instscip-go gomod github.com/golang/go/src go1.23.0 `encoding/xml`/ProcInst#Inst.), top)
1018 }
1019 }
1020 }
1021
1022 // SelectAttr finds an element attribute matching the requested 'key' and, if
1023 // found, returns a pointer to the matching attribute. The function returns
1024 // nil if no matching attribute is found. The key may include a namespace
1025 // prefix followed by a colon.
1026 func (e *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#) SelectAttrscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#SelectAttr().(key string) *Attrscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Attr# {
1027 space, skey := spaceDecomposescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/spaceDecompose().(key)
1028 for i, a := range e.Attrscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Attr. {
1029 if spaceMatchscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/spaceMatch().(space, a.Spacescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Attr#Space.) && skey == a.Keyscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Attr#Key. {
1030 return &e.Attrscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Attr.[i]
1031 }
1032 }
1033 return nil
1034 }
1035
1036 // SelectAttrValue finds an element attribute matching the requested 'key' and
1037 // returns its value if found. If no matching attribute is found, the function
1038 // returns the 'dflt' value instead. The key may include a namespace prefix
1039 // followed by a colon.
1040 func (e *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#) SelectAttrValuescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#SelectAttrValue().(key, dflt string) string {
1041 space, skey := spaceDecomposescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/spaceDecompose().(key)
1042 for _, a := range e.Attrscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Attr. {
1043 if spaceMatchscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/spaceMatch().(space, a.Spacescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Attr#Space.) && skey == a.Keyscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Attr#Key. {
1044 return a.Valuescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Attr#Value.
1045 }
1046 }
1047 return dflt
1048 }
1049
1050 // ChildElements returns all elements that are children of this element.
1051 func (e *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#) ChildElementsscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#ChildElements().() []*Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element# {
1052 return slicesscip-go gomod github.com/golang/go/src go1.23.0 slices/.Collectscip-go gomod github.com/golang/go/src go1.23.0 slices/Collect().(e.ChildElementsSeqscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#ChildElementsSeq().())
1053 }
1054
1055 // ChildElementsSeq returns an iterator over all child elements of this
1056 // element.
1057 func (e *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#) ChildElementsSeqscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#ChildElementsSeq().() iterscip-go gomod github.com/golang/go/src go1.23.0 iter/.Seqscip-go gomod github.com/golang/go/src go1.23.0 iter/Seq#[*Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#] {
1058 return func(yield func(*Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#) bool) {
1059 for _, t := range e.Childscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Child. {
1060 if c, ok := t.(*Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#); ok {
1061 if !yield(c) {
1062 return
1063 }
1064 }
1065 }
1066 }
1067 }
1068
1069 // SelectElement returns the first child element with the given 'tag' (i.e.,
1070 // name). The function returns nil if no child element matching the tag is
1071 // found. The tag may include a namespace prefix followed by a colon.
1072 func (e *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#) SelectElementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#SelectElement().(tag string) *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element# {
1073 for element := range e.SelectElementsSeqscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#SelectElementsSeq().(tag) {
1074 return element
1075 }
1076 return nil
1077 }
1078
1079 // SelectElements returns a slice of all child elements with the given 'tag'
1080 // (i.e., name). The tag may include a namespace prefix followed by a colon.
1081 func (e *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#) SelectElementsscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#SelectElements().(tag string) []*Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element# {
1082 return slicesscip-go gomod github.com/golang/go/src go1.23.0 slices/.Collectscip-go gomod github.com/golang/go/src go1.23.0 slices/Collect().(e.SelectElementsSeqscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#SelectElementsSeq().(tag))
1083 }
1084
1085 // SelectElementsSeq returns an iterator over all child elements with the
1086 // given 'tag' (i.e., name). The tag may include a namespace prefix followed
1087 // by a colon.
1088 func (e *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#) SelectElementsSeqscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#SelectElementsSeq().(tag string) iterscip-go gomod github.com/golang/go/src go1.23.0 iter/.Seqscip-go gomod github.com/golang/go/src go1.23.0 iter/Seq#[*Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#] {
1089 return func(yield func(*Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#) bool) {
1090 space, stag := spaceDecomposescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/spaceDecompose().(tag)
1091 for _, t := range e.Childscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Child. {
1092 if c, ok := t.(*Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#); ok && spaceMatchscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/spaceMatch().(space, c.Spacescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Space.) && stag == c.Tagscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Tag. {
1093 if !yield(c) {
1094 return
1095 }
1096 }
1097 }
1098 }
1099 }
1100
1101 // FindElement returns the first element matched by the XPath-like 'path'
1102 // string. The function returns nil if no child element is found using the
1103 // path. It panics if an invalid path string is supplied.
1104 func (e *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#) FindElementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#FindElement().(path string) *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element# {
1105 return e.FindElementPathscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#FindElementPath().(MustCompilePathscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/MustCompilePath().(path))
1106 }
1107
1108 // FindElementPath returns the first element matched by the 'path' object. The
1109 // function returns nil if no element is found using the path.
1110 func (e *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#) FindElementPathscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#FindElementPath().(path Pathscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Path#) *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element# {
1111 for element := range path.traversescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Path#traverse().(e) {
1112 return element
1113 }
1114 return nil
1115 }
1116
1117 // FindElements returns a slice of elements matched by the XPath-like 'path'
1118 // string. The function returns nil if no child element is found using the
1119 // path. It panics if an invalid path string is supplied.
1120 func (e *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#) FindElementsscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#FindElements().(path string) []*Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element# {
1121 return slicesscip-go gomod github.com/golang/go/src go1.23.0 slices/.Collectscip-go gomod github.com/golang/go/src go1.23.0 slices/Collect().(e.FindElementsSeqscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#FindElementsSeq().(path))
1122 }
1123
1124 // FindElementsSeq returns an iterator over elements matched by the XPath-like
1125 // 'path' string. This function uses Go's iterator support for
1126 // memory-efficient traversal. It panics if an invalid path string is
1127 // supplied.
1128 func (e *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#) FindElementsSeqscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#FindElementsSeq().(path string) iterscip-go gomod github.com/golang/go/src go1.23.0 iter/.Seqscip-go gomod github.com/golang/go/src go1.23.0 iter/Seq#[*Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#] {
1129 return e.FindElementsPathSeqscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#FindElementsPathSeq().(MustCompilePathscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/MustCompilePath().(path))
1130 }
1131
1132 // FindElementsPath returns a slice of elements matched by the 'path' object.
1133 func (e *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#) FindElementsPathscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#FindElementsPath().(path Pathscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Path#) []*Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element# {
1134 return slicesscip-go gomod github.com/golang/go/src go1.23.0 slices/.Collectscip-go gomod github.com/golang/go/src go1.23.0 slices/Collect().(e.FindElementsPathSeqscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#FindElementsPathSeq().(path))
1135 }
1136
1137 // FindElementsPathSeq returns an iterator over elements matched by the 'path'
1138 // object.
1139 func (e *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#) FindElementsPathSeqscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#FindElementsPathSeq().(path Pathscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Path#) iterscip-go gomod github.com/golang/go/src go1.23.0 iter/.Seqscip-go gomod github.com/golang/go/src go1.23.0 iter/Seq#[*Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#] {
1140 return path.traversescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Path#traverse().(e)
1141 }
1142
1143 // NotNil returns the receiver element if it isn't nil; otherwise, it returns
1144 // an unparented element with an empty string tag. This function simplifies
1145 // the task of writing code to ignore not-found results from element queries.
1146 // For example, instead of writing this:
1147 //
1148 // if e := doc.SelectElement("enabled"); e != nil {
1149 // e.SetText("true")
1150 // }
1151 //
1152 // You could write this:
1153 //
1154 // doc.SelectElement("enabled").NotNil().SetText("true")
1155 func (e *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#) NotNilscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#NotNil().() *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element# {
1156 if e == nil {
1157 return NewElementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/NewElement().("")
1158 }
1159 return e
1160 }
1161
1162 // GetPath returns the absolute path of the element. The absolute path is the
1163 // full path from the document's root.
1164 func (e *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#) GetPathscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#GetPath().() string {
1165 path := []string{}
1166 for seg := e; seg != nil; seg = seg.Parentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Parent().() {
1167 if seg.Tagscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Tag. != "" {
1168 path = append(path, seg.Tagscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Tag.)
1169 }
1170 }
1171
1172 // Reverse the path.
1173 for i, j := 0, len(path)-1; i < j; i, j = i+1, j-1 {
1174 path[i], path[j] = path[j], path[i]
1175 }
1176
1177 return "/" + stringsscip-go gomod github.com/golang/go/src go1.23.0 strings/.Joinscip-go gomod github.com/golang/go/src go1.23.0 strings/Join().(path, "/")
1178 }
1179
1180 // GetRelativePath returns the path of this element relative to the 'source'
1181 // element. If the two elements are not part of the same element tree, then
1182 // the function returns the empty string.
1183 func (e *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#) GetRelativePathscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#GetRelativePath().(source *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#) string {
1184 var path []*Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#
1185
1186 if source == nil {
1187 return ""
1188 }
1189
1190 // Build a reverse path from the element toward the root. Stop if the
1191 // source element is encountered.
1192 var seg *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#
1193 for seg = e; seg != nil && seg != source; seg = seg.Parentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Parent().() {
1194 path = append(path, seg)
1195 }
1196
1197 // If we found the source element, reverse the path and compose the
1198 // string.
1199 if seg == source {
1200 if len(path) == 0 {
1201 return "."
1202 }
1203 parts := []string{}
1204 for i := len(path) - 1; i >= 0; i-- {
1205 parts = append(parts, path[i].Tagscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Tag.)
1206 }
1207 return "./" + stringsscip-go gomod github.com/golang/go/src go1.23.0 strings/.Joinscip-go gomod github.com/golang/go/src go1.23.0 strings/Join().(parts, "/")
1208 }
1209
1210 // The source wasn't encountered, so climb from the source element toward
1211 // the root of the tree until an element in the reversed path is
1212 // encountered.
1213
1214 findPathIndex := func(e *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#, path []*Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#) int {
1215 for i, ee := range path {
1216 if e == ee {
1217 return i
1218 }
1219 }
1220 return -1
1221 }
1222
1223 climb := 0
1224 for seg = source; seg != nil; seg = seg.Parentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Parent().() {
1225 i := findPathIndex(seg, path)
1226 if i >= 0 {
1227 path = path[:i] // truncate at found segment
1228 break
1229 }
1230 climb++
1231 }
1232
1233 // No element in the reversed path was encountered, so the two elements
1234 // must not be part of the same tree.
1235 if seg == nil {
1236 return ""
1237 }
1238
1239 // Reverse the (possibly truncated) path and prepend ".." segments to
1240 // climb.
1241 parts := []string{}
1242 for i := 0; i < climb; i++ {
1243 parts = append(parts, "..")
1244 }
1245 for i := len(path) - 1; i >= 0; i-- {
1246 parts = append(parts, path[i].Tagscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Tag.)
1247 }
1248 return stringsscip-go gomod github.com/golang/go/src go1.23.0 strings/.Joinscip-go gomod github.com/golang/go/src go1.23.0 strings/Join().(parts, "/")
1249 }
1250
1251 // IndentWithSettings modifies the element and its child tree by inserting
1252 // character data tokens containing newlines and indentation. The behavior of
1253 // the indentation algorithm is configured by the indent settings. Because
1254 // this function indents the element as if it were at the root of a document,
1255 // it is most useful when called just before writing the element as an XML
1256 // fragment using WriteTo.
1257 func (e *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#) IndentWithSettingsscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#IndentWithSettings().(s *IndentSettingsscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/IndentSettings#) {
1258 e.indentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#indent().(1, getIndentFuncscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/getIndentFunc().(s), s)
1259 }
1260
1261 // indent recursively inserts proper indentation between an XML element's
1262 // child tokens.
1263 func (e *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#) indentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#indent().(depth int, indent indentFuncscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/indentFunc#, s *IndentSettingsscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/IndentSettings#) {
1264 e.stripIndentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#stripIndent().(s)
1265 n := len(e.Childscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Child.)
1266 if n == 0 {
1267 return
1268 }
1269
1270 oldChild := e.Childscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Child.
1271 e.Childscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Child. = make([]Tokenscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Token#, 0, n*2+1)
1272 isCharData, firstNonCharData := false, true
1273 for _, c := range oldChild {
1274 // Insert NL+indent before child if it's not character data.
1275 // Exceptions: when it's the first non-character-data child, or when
1276 // the child is at root depth.
1277 _, isCharData = c.(*CharDatascip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/CharData#)
1278 if !isCharData {
1279 if !firstNonCharData || depth > 0 {
1280 s := indent(depth)
1281 if s != "" {
1282 newCharDatascip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/newCharData().(s, whitespaceFlagscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/whitespaceFlag., e)
1283 }
1284 }
1285 firstNonCharData = false
1286 }
1287
1288 e.addChildscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#addChild().(c)
1289
1290 // Recursively process child elements.
1291 if ce, ok := c.(*Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#); ok {
1292 ce.indentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#indent().(depth+1, indent, s)
1293 }
1294 }
1295
1296 // Insert NL+indent before the last child.
1297 if !isCharData {
1298 if !firstNonCharData || depth > 0 {
1299 s := indent(depth - 1)
1300 if s != "" {
1301 newCharDatascip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/newCharData().(s, whitespaceFlagscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/whitespaceFlag., e)
1302 }
1303 }
1304 }
1305 }
1306
1307 // stripIndent removes any previously inserted indentation.
1308 func (e *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#) stripIndentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#stripIndent().(s *IndentSettingsscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/IndentSettings#) {
1309 // Count the number of non-indent child tokens
1310 n := len(e.Childscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Child.)
1311 for _, c := range e.Childscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Child. {
1312 if cd, ok := c.(*CharDatascip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/CharData#); ok && cd.IsWhitespacescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/CharData#IsWhitespace().() {
1313 n--
1314 }
1315 }
1316 if n == len(e.Childscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Child.) {
1317 return
1318 }
1319 if n == 0 && len(e.Childscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Child.) == 1 && s.PreserveLeafWhitespacescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/IndentSettings#PreserveLeafWhitespace. {
1320 return
1321 }
1322
1323 // Strip out indent CharData
1324 newChild := make([]Tokenscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Token#, n)
1325 j := 0
1326 for _, c := range e.Childscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Child. {
1327 if cd, ok := c.(*CharDatascip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/CharData#); ok && cd.IsWhitespacescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/CharData#IsWhitespace().() {
1328 continue
1329 }
1330 newChild[j] = c
1331 newChild[j].setIndexscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Token#setIndex.(j)
1332 j++
1333 }
1334 e.Childscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Child. = newChild
1335 }
1336
1337 // stripTrailingWhitespace removes any trailing whitespace CharData tokens
1338 // from the element's children.
1339 func (e *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#) stripTrailingWhitespacescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#stripTrailingWhitespace().() {
1340 for i := len(e.Childscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Child.) - 1; i >= 0; i-- {
1341 if cd, ok := e.Childscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Child.[i].(*CharDatascip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/CharData#); !ok || !cd.IsWhitespacescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/CharData#IsWhitespace().() {
1342 e.Childscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Child. = e.Childscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Child.[:i+1]
1343 return
1344 }
1345 }
1346 }
1347
1348 // dup duplicates the element.
1349 func (e *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#) dupscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#dup().(parent *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#) Tokenscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Token# {
1350 ne := &Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#{
1351 Spacescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Space.: e.Spacescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Space.,
1352 Tagscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Tag.: e.Tagscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Tag.,
1353 Attrscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Attr.: make([]Attrscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Attr#, len(e.Attrscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Attr.)),
1354 Childscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Child.: make([]Tokenscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Token#, len(e.Childscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Child.)),
1355 parentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#parent.: parent,
1356 indexscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#index.: e.indexscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#index.,
1357 }
1358 for i, t := range e.Childscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Child. {
1359 ne.Childscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Child.[i] = t.dupscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Token#dup.(ne)
1360 }
1361 copy(ne.Attrscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Attr., e.Attrscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Attr.)
1362 return ne
1363 }
1364
1365 // NextSibling returns this element's next sibling element. It returns nil if
1366 // there is no next sibling element.
1367 func (e *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#) NextSiblingscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#NextSibling().() *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element# {
1368 if e.parentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#parent. == nil {
1369 return nil
1370 }
1371 for i := e.indexscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#index. + 1; i < len(e.parentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#parent..Childscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Child.); i++ {
1372 if s, ok := e.parentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#parent..Childscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Child.[i].(*Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#); ok {
1373 return s
1374 }
1375 }
1376 return nil
1377 }
1378
1379 // PrevSibling returns this element's preceding sibling element. It returns
1380 // nil if there is no preceding sibling element.
1381 func (e *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#) PrevSiblingscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#PrevSibling().() *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element# {
1382 if e.parentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#parent. == nil {
1383 return nil
1384 }
1385 for i := e.indexscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#index. - 1; i >= 0; i-- {
1386 if s, ok := e.parentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#parent..Childscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Child.[i].(*Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#); ok {
1387 return s
1388 }
1389 }
1390 return nil
1391 }
1392
1393 // Parent returns this element's parent element. It returns nil if this
1394 // element has no parent.
1395 func (e *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#) Parentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Parent().() *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element# {
1396 return e.parentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#parent.
1397 }
1398
1399 // Index returns the index of this element within its parent element's
1400 // list of child tokens. If this element has no parent, then the function
1401 // returns -1.
1402 func (e *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#) Indexscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Index().() int {
1403 return e.indexscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#index.
1404 }
1405
1406 // WriteTo serializes the element to the writer w.
1407 func (e *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#) WriteToscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#WriteTo().(w Writerscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Writer#, s *WriteSettingsscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/WriteSettings#) {
1408 w.WriteBytescip-go gomod github.com/golang/go/src go1.23.0 io/ByteWriter#WriteByte().('<')
1409 w.WriteStringscip-go gomod github.com/golang/go/src go1.23.0 io/StringWriter#WriteString().(e.FullTagscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#FullTag().())
1410 for _, a := range e.Attrscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Attr. {
1411 w.WriteBytescip-go gomod github.com/golang/go/src go1.23.0 io/ByteWriter#WriteByte().(' ')
1412 a.WriteToscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Attr#WriteTo().(w, s)
1413 }
1414 if len(e.Childscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Child.) > 0 {
1415 w.WriteBytescip-go gomod github.com/golang/go/src go1.23.0 io/ByteWriter#WriteByte().('>')
1416 for _, c := range e.Childscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Child. {
1417 c.WriteToscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Token#WriteTo.(w, s)
1418 }
1419 w.Writescip-go gomod github.com/golang/go/src go1.23.0 io/Writer#Write().([]byte{'<', '/'})
1420 w.WriteStringscip-go gomod github.com/golang/go/src go1.23.0 io/StringWriter#WriteString().(e.FullTagscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#FullTag().())
1421 w.WriteBytescip-go gomod github.com/golang/go/src go1.23.0 io/ByteWriter#WriteByte().('>')
1422 } else {
1423 if s.CanonicalEndTagsscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/WriteSettings#CanonicalEndTags. {
1424 w.Writescip-go gomod github.com/golang/go/src go1.23.0 io/Writer#Write().([]byte{'>', '<', '/'})
1425 w.WriteStringscip-go gomod github.com/golang/go/src go1.23.0 io/StringWriter#WriteString().(e.FullTagscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#FullTag().())
1426 w.WriteBytescip-go gomod github.com/golang/go/src go1.23.0 io/ByteWriter#WriteByte().('>')
1427 } else {
1428 w.Writescip-go gomod github.com/golang/go/src go1.23.0 io/Writer#Write().([]byte{'/', '>'})
1429 }
1430 }
1431 }
1432
1433 // setParent replaces this element token's parent.
1434 func (e *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#) setParentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#setParent().(parent *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#) {
1435 e.parentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#parent. = parent
1436 }
1437
1438 // setIndex sets this element token's index within its parent's Child slice.
1439 func (e *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#) setIndexscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#setIndex().(index int) {
1440 e.indexscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#index. = index
1441 }
1442
1443 // addChild adds a child token to the element e.
1444 func (e *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#) addChildscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#addChild().(t Tokenscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Token#) {
1445 t.setParentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Token#setParent.(e)
1446 t.setIndexscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Token#setIndex.(len(e.Childscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Child.))
1447 e.Childscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Child. = append(e.Childscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Child., t)
1448 }
1449
1450 // CreateAttr creates an attribute with the specified 'key' and 'value' and
1451 // adds it to this element. If an attribute with same key already exists on
1452 // this element, then its value is replaced. The key may include a namespace
1453 // prefix followed by a colon.
1454 func (e *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#) CreateAttrscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#CreateAttr().(key, value string) *Attrscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Attr# {
1455 space, skey := spaceDecomposescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/spaceDecompose().(key)
1456
1457 for i, a := range e.Attrscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Attr. {
1458 if space == a.Spacescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Attr#Space. && skey == a.Keyscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Attr#Key. {
1459 e.Attrscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Attr.[i].Valuescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Attr#Value. = value
1460 return &e.Attrscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Attr.[i]
1461 }
1462 }
1463
1464 i := e.addAttrscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#addAttr().(space, skey, value)
1465 return &e.Attrscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Attr.[i]
1466 }
1467
1468 // addAttr is a helper function that adds an attribute to an element. Returns
1469 // the index of the added attribute.
1470 func (e *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#) addAttrscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#addAttr().(space, key, value string) int {
1471 a := Attrscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Attr#{
1472 Spacescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Attr#Space.: space,
1473 Keyscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Attr#Key.: key,
1474 Valuescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Attr#Value.: value,
1475 elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Attr#element.: e,
1476 }
1477 e.Attrscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Attr. = append(e.Attrscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Attr., a)
1478 return len(e.Attrscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Attr.) - 1
1479 }
1480
1481 // RemoveAttr removes the first attribute of this element whose key matches
1482 // 'key'. It returns a copy of the removed attribute if a match is found. If
1483 // no match is found, it returns nil. The key may include a namespace prefix
1484 // followed by a colon.
1485 func (e *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#) RemoveAttrscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#RemoveAttr().(key string) *Attrscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Attr# {
1486 space, skey := spaceDecomposescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/spaceDecompose().(key)
1487 for i, a := range e.Attrscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Attr. {
1488 if space == a.Spacescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Attr#Space. && skey == a.Keyscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Attr#Key. {
1489 e.Attrscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Attr. = append(e.Attrscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Attr.[0:i], e.Attrscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Attr.[i+1:]...)
1490 return &Attrscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Attr#{
1491 Spacescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Attr#Space.: a.Spacescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Attr#Space.,
1492 Keyscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Attr#Key.: a.Keyscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Attr#Key.,
1493 Valuescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Attr#Value.: a.Valuescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Attr#Value.,
1494 elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Attr#element.: nil,
1495 }
1496 }
1497 }
1498 return nil
1499 }
1500
1501 // SortAttrs sorts this element's attributes lexicographically by key.
1502 func (e *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#) SortAttrsscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#SortAttrs().() {
1503 slicesscip-go gomod github.com/golang/go/src go1.23.0 slices/.SortFuncscip-go gomod github.com/golang/go/src go1.23.0 slices/SortFunc().(e.Attrscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#Attr., func(a, b Attrscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Attr#) int {
1504 if v := stringsscip-go gomod github.com/golang/go/src go1.23.0 strings/.Comparescip-go gomod github.com/golang/go/src go1.23.0 strings/Compare().(a.Spacescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Attr#Space., b.Spacescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Attr#Space.); v != 0 {
1505 return v
1506 }
1507 return stringsscip-go gomod github.com/golang/go/src go1.23.0 strings/.Comparescip-go gomod github.com/golang/go/src go1.23.0 strings/Compare().(a.Keyscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Attr#Key., b.Keyscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Attr#Key.)
1508 })
1509 }
1510
1511 // FullKey returns this attribute's complete key, including namespace prefix
1512 // if present.
1513 func (a *Attrscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Attr#) FullKeyscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Attr#FullKey().() string {
1514 if a.Spacescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Attr#Space. == "" {
1515 return a.Keyscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Attr#Key.
1516 }
1517 return a.Spacescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Attr#Space. + ":" + a.Keyscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Attr#Key.
1518 }
1519
1520 // Element returns a pointer to the element containing this attribute.
1521 func (a *Attrscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Attr#) Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Attr#Element().() *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element# {
1522 return a.elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Attr#element.
1523 }
1524
1525 // NamespaceURI returns the XML namespace URI associated with this attribute.
1526 // The function returns the empty string if the attribute is unprefixed or
1527 // if the attribute is part of the XML default namespace.
1528 func (a *Attrscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Attr#) NamespaceURIscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Attr#NamespaceURI().() string {
1529 if a.Spacescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Attr#Space. == "" {
1530 return ""
1531 }
1532 return a.elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Attr#element..findLocalNamespaceURIscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#findLocalNamespaceURI().(a.Spacescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Attr#Space.)
1533 }
1534
1535 // WriteTo serializes the attribute to the writer.
1536 func (a *Attrscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Attr#) WriteToscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Attr#WriteTo().(w Writerscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Writer#, s *WriteSettingsscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/WriteSettings#) {
1537 w.WriteStringscip-go gomod github.com/golang/go/src go1.23.0 io/StringWriter#WriteString().(a.FullKeyscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Attr#FullKey().())
1538 if s.AttrSingleQuotescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/WriteSettings#AttrSingleQuote. {
1539 w.WriteStringscip-go gomod github.com/golang/go/src go1.23.0 io/StringWriter#WriteString().(`='`)
1540 } else {
1541 w.WriteStringscip-go gomod github.com/golang/go/src go1.23.0 io/StringWriter#WriteString().(`="`)
1542 }
1543 var m escapeModescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/escapeMode#
1544 if s.CanonicalAttrValscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/WriteSettings#CanonicalAttrVal. && !s.AttrSingleQuotescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/WriteSettings#AttrSingleQuote. {
1545 m = escapeCanonicalAttrscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/escapeCanonicalAttr.
1546 } else {
1547 m = escapeNormalscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/escapeNormal.
1548 }
1549 escapeStringscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/escapeString().(w, a.Valuescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Attr#Value., m)
1550 if s.AttrSingleQuotescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/WriteSettings#AttrSingleQuote. {
1551 w.WriteBytescip-go gomod github.com/golang/go/src go1.23.0 io/ByteWriter#WriteByte().('\'')
1552 } else {
1553 w.WriteBytescip-go gomod github.com/golang/go/src go1.23.0 io/ByteWriter#WriteByte().('"')
1554 }
1555 }
1556
1557 // NewText creates an unparented CharData token containing simple text data.
1558 func NewTextscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/NewText().(text string) *CharDatascip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/CharData# {
1559 return newCharDatascip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/newCharData().(text, 0, nil)
1560 }
1561
1562 // NewCData creates an unparented XML character CDATA section with 'data' as
1563 // its content.
1564 func NewCDatascip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/NewCData().(data string) *CharDatascip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/CharData# {
1565 return newCharDatascip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/newCharData().(data, cdataFlagscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/cdataFlag., nil)
1566 }
1567
1568 // NewCharData creates an unparented CharData token containing simple text
1569 // data.
1570 //
1571 // Deprecated: NewCharData is deprecated. Instead, use NewText, which does the
1572 // same thing.
1573 func NewCharDatascip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/NewCharData().(data string) *CharDatascip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/CharData# {
1574 return newCharDatascip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/newCharData().(data, 0, nil)
1575 }
1576
1577 // newCharData creates a character data token and binds it to a parent
1578 // element. If parent is nil, the CharData token remains unbound.
1579 func newCharDatascip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/newCharData().(data string, flags charDataFlagsscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/charDataFlags#, parent *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#) *CharDatascip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/CharData# {
1580 c := &CharDatascip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/CharData#{
1581 Datascip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/CharData#Data.: data,
1582 parentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/CharData#parent.: nil,
1583 indexscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/CharData#index.: -1,
1584 flagsscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/CharData#flags.: flags,
1585 }
1586 if parent != nil {
1587 parent.addChildscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#addChild().(c)
1588 }
1589 return c
1590 }
1591
1592 // CreateText creates a CharData token containing simple text data and adds it
1593 // to the end of this element's list of child tokens.
1594 func (e *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#) CreateTextscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#CreateText().(text string) *CharDatascip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/CharData# {
1595 return newCharDatascip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/newCharData().(text, 0, e)
1596 }
1597
1598 // CreateCData creates a CharData token containing a CDATA section with 'data'
1599 // as its content and adds it to the end of this element's list of child
1600 // tokens.
1601 func (e *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#) CreateCDatascip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#CreateCData().(data string) *CharDatascip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/CharData# {
1602 return newCharDatascip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/newCharData().(data, cdataFlagscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/cdataFlag., e)
1603 }
1604
1605 // CreateCharData creates a CharData token containing simple text data and
1606 // adds it to the end of this element's list of child tokens.
1607 //
1608 // Deprecated: CreateCharData is deprecated. Instead, use CreateText, which
1609 // does the same thing.
1610 func (e *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#) CreateCharDatascip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#CreateCharData().(data string) *CharDatascip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/CharData# {
1611 return e.CreateTextscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#CreateText().(data)
1612 }
1613
1614 // SetData modifies the content of the CharData token. In the case of a
1615 // CharData token containing simple text, the simple text is modified. In the
1616 // case of a CharData token containing a CDATA section, the CDATA section's
1617 // content is modified.
1618 func (c *CharDatascip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/CharData#) SetDatascip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/CharData#SetData().(text string) {
1619 c.Datascip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/CharData#Data. = text
1620 if isWhitespacescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/isWhitespace().(text) {
1621 c.flagsscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/CharData#flags. |= whitespaceFlagscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/whitespaceFlag.
1622 } else {
1623 c.flagsscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/CharData#flags. &= ^whitespaceFlagscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/whitespaceFlag.
1624 }
1625 }
1626
1627 // IsCData returns true if this CharData token is contains a CDATA section. It
1628 // returns false if the CharData token contains simple text.
1629 func (c *CharDatascip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/CharData#) IsCDatascip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/CharData#IsCData().() bool {
1630 return (c.flagsscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/CharData#flags. & cdataFlagscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/cdataFlag.) != 0
1631 }
1632
1633 // IsWhitespace returns true if this CharData token contains only whitespace.
1634 func (c *CharDatascip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/CharData#) IsWhitespacescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/CharData#IsWhitespace().() bool {
1635 return (c.flagsscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/CharData#flags. & whitespaceFlagscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/whitespaceFlag.) != 0
1636 }
1637
1638 // Parent returns this CharData token's parent element, or nil if it has no
1639 // parent.
1640 func (c *CharDatascip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/CharData#) Parentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/CharData#Parent().() *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element# {
1641 return c.parentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/CharData#parent.
1642 }
1643
1644 // Index returns the index of this CharData token within its parent element's
1645 // list of child tokens. If this CharData token has no parent, then the
1646 // function returns -1.
1647 func (c *CharDatascip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/CharData#) Indexscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/CharData#Index().() int {
1648 return c.indexscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/CharData#index.
1649 }
1650
1651 // WriteTo serializes character data to the writer.
1652 func (c *CharDatascip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/CharData#) WriteToscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/CharData#WriteTo().(w Writerscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Writer#, s *WriteSettingsscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/WriteSettings#) {
1653 if c.IsCDatascip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/CharData#IsCData().() {
1654 w.WriteStringscip-go gomod github.com/golang/go/src go1.23.0 io/StringWriter#WriteString().(`<![CDATA[`)
1655 sanitizeCDatascip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/sanitizeCData().(w, c.Datascip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/CharData#Data.)
1656 w.WriteStringscip-go gomod github.com/golang/go/src go1.23.0 io/StringWriter#WriteString().(`]]>`)
1657 } else {
1658 var m escapeModescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/escapeMode#
1659 if s.CanonicalTextscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/WriteSettings#CanonicalText. {
1660 m = escapeCanonicalTextscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/escapeCanonicalText.
1661 } else {
1662 m = escapeNormalscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/escapeNormal.
1663 }
1664 escapeStringscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/escapeString().(w, c.Datascip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/CharData#Data., m)
1665 }
1666 }
1667
1668 // dup duplicates the character data.
1669 func (c *CharDatascip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/CharData#) dupscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/CharData#dup().(parent *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#) Tokenscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Token# {
1670 return &CharDatascip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/CharData#{
1671 Datascip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/CharData#Data.: c.Datascip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/CharData#Data.,
1672 flagsscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/CharData#flags.: c.flagsscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/CharData#flags.,
1673 parentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/CharData#parent.: parent,
1674 indexscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/CharData#index.: c.indexscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/CharData#index.,
1675 }
1676 }
1677
1678 // setParent replaces the character data token's parent.
1679 func (c *CharDatascip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/CharData#) setParentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/CharData#setParent().(parent *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#) {
1680 c.parentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/CharData#parent. = parent
1681 }
1682
1683 // setIndex sets the CharData token's index within its parent element's Child
1684 // slice.
1685 func (c *CharDatascip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/CharData#) setIndexscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/CharData#setIndex().(index int) {
1686 c.indexscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/CharData#index. = index
1687 }
1688
1689 // NewComment creates an unparented comment token.
1690 func NewCommentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/NewComment().(comment string) *Commentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Comment# {
1691 return newCommentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/newComment().(comment, nil)
1692 }
1693
1694 // NewComment creates a comment token and sets its parent element to 'parent'.
1695 func newCommentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/newComment().(comment string, parent *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#) *Commentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Comment# {
1696 c := &Commentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Comment#{
1697 Datascip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Comment#Data.: comment,
1698 parentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Comment#parent.: nil,
1699 indexscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Comment#index.: -1,
1700 }
1701 if parent != nil {
1702 parent.addChildscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#addChild().(c)
1703 }
1704 return c
1705 }
1706
1707 // CreateComment creates a comment token using the specified 'comment' string
1708 // and adds it as the last child token of this element.
1709 func (e *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#) CreateCommentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#CreateComment().(comment string) *Commentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Comment# {
1710 return newCommentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/newComment().(comment, e)
1711 }
1712
1713 // dup duplicates the comment.
1714 func (c *Commentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Comment#) dupscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Comment#dup().(parent *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#) Tokenscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Token# {
1715 return &Commentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Comment#{
1716 Datascip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Comment#Data.: c.Datascip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Comment#Data.,
1717 parentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Comment#parent.: parent,
1718 indexscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Comment#index.: c.indexscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Comment#index.,
1719 }
1720 }
1721
1722 // Parent returns comment token's parent element, or nil if it has no parent.
1723 func (c *Commentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Comment#) Parentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Comment#Parent().() *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element# {
1724 return c.parentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Comment#parent.
1725 }
1726
1727 // Index returns the index of this Comment token within its parent element's
1728 // list of child tokens. If this Comment token has no parent, then the
1729 // function returns -1.
1730 func (c *Commentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Comment#) Indexscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Comment#Index().() int {
1731 return c.indexscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Comment#index.
1732 }
1733
1734 // WriteTo serialies the comment to the writer.
1735 func (c *Commentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Comment#) WriteToscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Comment#WriteTo().(w Writerscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Writer#, s *WriteSettingsscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/WriteSettings#) {
1736 w.WriteStringscip-go gomod github.com/golang/go/src go1.23.0 io/StringWriter#WriteString().("<!--")
1737 sanitizeCommentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/sanitizeComment().(w, c.Datascip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Comment#Data.)
1738 w.WriteStringscip-go gomod github.com/golang/go/src go1.23.0 io/StringWriter#WriteString().("-->")
1739 }
1740
1741 // setParent replaces the comment token's parent.
1742 func (c *Commentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Comment#) setParentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Comment#setParent().(parent *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#) {
1743 c.parentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Comment#parent. = parent
1744 }
1745
1746 // setIndex sets the Comment token's index within its parent element's Child
1747 // slice.
1748 func (c *Commentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Comment#) setIndexscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Comment#setIndex().(index int) {
1749 c.indexscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Comment#index. = index
1750 }
1751
1752 // NewDirective creates an unparented XML directive token.
1753 func NewDirectivescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/NewDirective().(data string) *Directivescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Directive# {
1754 return newDirectivescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/newDirective().(data, nil)
1755 }
1756
1757 // newDirective creates an XML directive and binds it to a parent element. If
1758 // parent is nil, the Directive remains unbound.
1759 func newDirectivescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/newDirective().(data string, parent *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#) *Directivescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Directive# {
1760 d := &Directivescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Directive#{
1761 Datascip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Directive#Data.: data,
1762 parentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Directive#parent.: nil,
1763 indexscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Directive#index.: -1,
1764 }
1765 if parent != nil {
1766 parent.addChildscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#addChild().(d)
1767 }
1768 return d
1769 }
1770
1771 // CreateDirective creates an XML directive token with the specified 'data'
1772 // value and adds it as the last child token of this element.
1773 func (e *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#) CreateDirectivescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#CreateDirective().(data string) *Directivescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Directive# {
1774 return newDirectivescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/newDirective().(data, e)
1775 }
1776
1777 // dup duplicates the directive.
1778 func (d *Directivescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Directive#) dupscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Directive#dup().(parent *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#) Tokenscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Token# {
1779 return &Directivescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Directive#{
1780 Datascip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Directive#Data.: d.Datascip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Directive#Data.,
1781 parentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Directive#parent.: parent,
1782 indexscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Directive#index.: d.indexscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Directive#index.,
1783 }
1784 }
1785
1786 // Parent returns directive token's parent element, or nil if it has no
1787 // parent.
1788 func (d *Directivescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Directive#) Parentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Directive#Parent().() *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element# {
1789 return d.parentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Directive#parent.
1790 }
1791
1792 // Index returns the index of this Directive token within its parent element's
1793 // list of child tokens. If this Directive token has no parent, then the
1794 // function returns -1.
1795 func (d *Directivescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Directive#) Indexscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Directive#Index().() int {
1796 return d.indexscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Directive#index.
1797 }
1798
1799 // WriteTo serializes the XML directive to the writer.
1800 func (d *Directivescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Directive#) WriteToscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Directive#WriteTo().(w Writerscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Writer#, s *WriteSettingsscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/WriteSettings#) {
1801 w.WriteStringscip-go gomod github.com/golang/go/src go1.23.0 io/StringWriter#WriteString().("<!")
1802 sanitizeDirectivescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/sanitizeDirective().(w, d.Datascip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Directive#Data.)
1803 w.WriteStringscip-go gomod github.com/golang/go/src go1.23.0 io/StringWriter#WriteString().(">")
1804 }
1805
1806 // setParent replaces the directive token's parent.
1807 func (d *Directivescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Directive#) setParentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Directive#setParent().(parent *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#) {
1808 d.parentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Directive#parent. = parent
1809 }
1810
1811 // setIndex sets the Directive token's index within its parent element's Child
1812 // slice.
1813 func (d *Directivescip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Directive#) setIndexscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Directive#setIndex().(index int) {
1814 d.indexscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Directive#index. = index
1815 }
1816
1817 // NewProcInst creates an unparented XML processing instruction.
1818 func NewProcInstscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/NewProcInst().(target, inst string) *ProcInstscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/ProcInst# {
1819 return newProcInstscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/newProcInst().(target, inst, nil)
1820 }
1821
1822 // newProcInst creates an XML processing instruction and binds it to a parent
1823 // element. If parent is nil, the ProcInst remains unbound.
1824 func newProcInstscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/newProcInst().(target, inst string, parent *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#) *ProcInstscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/ProcInst# {
1825 p := &ProcInstscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/ProcInst#{
1826 Targetscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/ProcInst#Target.: target,
1827 Instscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/ProcInst#Inst.: inst,
1828 parentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/ProcInst#parent.: nil,
1829 indexscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/ProcInst#index.: -1,
1830 }
1831 if parent != nil {
1832 parent.addChildscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#addChild().(p)
1833 }
1834 return p
1835 }
1836
1837 // CreateProcInst creates an XML processing instruction token with the
1838 // specified 'target' and instruction 'inst'. It is then added as the last
1839 // child token of this element.
1840 func (e *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#) CreateProcInstscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#CreateProcInst().(target, inst string) *ProcInstscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/ProcInst# {
1841 return newProcInstscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/newProcInst().(target, inst, e)
1842 }
1843
1844 // dup duplicates the procinst.
1845 func (p *ProcInstscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/ProcInst#) dupscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/ProcInst#dup().(parent *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#) Tokenscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Token# {
1846 return &ProcInstscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/ProcInst#{
1847 Targetscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/ProcInst#Target.: p.Targetscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/ProcInst#Target.,
1848 Instscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/ProcInst#Inst.: p.Instscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/ProcInst#Inst.,
1849 parentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/ProcInst#parent.: parent,
1850 indexscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/ProcInst#index.: p.indexscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/ProcInst#index.,
1851 }
1852 }
1853
1854 // Parent returns processing instruction token's parent element, or nil if it
1855 // has no parent.
1856 func (p *ProcInstscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/ProcInst#) Parentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/ProcInst#Parent().() *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element# {
1857 return p.parentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/ProcInst#parent.
1858 }
1859
1860 // Index returns the index of this ProcInst token within its parent element's
1861 // list of child tokens. If this ProcInst token has no parent, then the
1862 // function returns -1.
1863 func (p *ProcInstscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/ProcInst#) Indexscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/ProcInst#Index().() int {
1864 return p.indexscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/ProcInst#index.
1865 }
1866
1867 // WriteTo serializes the processing instruction to the writer.
1868 func (p *ProcInstscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/ProcInst#) WriteToscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/ProcInst#WriteTo().(w Writerscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Writer#, s *WriteSettingsscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/WriteSettings#) {
1869 w.WriteStringscip-go gomod github.com/golang/go/src go1.23.0 io/StringWriter#WriteString().("<?")
1870 sanitizeProcInstscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/sanitizeProcInst().(w, p.Targetscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/ProcInst#Target.)
1871 if p.Instscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/ProcInst#Inst. != "" {
1872 w.WriteBytescip-go gomod github.com/golang/go/src go1.23.0 io/ByteWriter#WriteByte().(' ')
1873 sanitizeProcInstscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/sanitizeProcInst().(w, p.Instscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/ProcInst#Inst.)
1874 }
1875 w.WriteStringscip-go gomod github.com/golang/go/src go1.23.0 io/StringWriter#WriteString().("?>")
1876 }
1877
1878 // setParent replaces the processing instruction token's parent.
1879 func (p *ProcInstscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/ProcInst#) setParentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/ProcInst#setParent().(parent *Elementscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/Element#) {
1880 p.parentscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/ProcInst#parent. = parent
1881 }
1882
1883 // setIndex sets the processing instruction token's index within its parent
1884 // element's Child slice.
1885 func (p *ProcInstscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/ProcInst#) setIndexscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/ProcInst#setIndex().(index int) {
1886 p.indexscip-go gomod github.com/beevik/etree . `github.com/beevik/etree`/ProcInst#index. = index
1887 }