Standard library / encoding/xml

encoding/xml.StartElement.Copy()

Copies the start token including its attribute slice. Expected stdout: '7\n'.

Formal Syntax & Structure

go syntaxgo
func (e StartElement) Copy() StartElement

Return Value

StartElement

Copied start element.

Working Example

Example Snippetgo
package main
import (  "encoding/xml"  "fmt")
func must(e error) {  if e != nil {    panic(e)  }}
func main() {  v := xml.StartElement{Name: xml.Name{Local: "a"}, Attr: []xml.Attr{{Name: xml.Name{Local: "id"}, Value: "7"}}}  c := v.Copy()  v.Attr[0].Value = "8"  fmt.Println(c.Attr[0].Value)}
Go Reference