This is a creation in Article, where the information may have evolved or changed.
Package main import ("Bufio" "bytes" "IO" "OS" "Unicode") const (Stat_none = Iota Stat_group stat_key stat_value Stat _comment) type Attr struct {Name string Value string comment string next *attr} type Element struct {element String Attr *attr Next *element} type Decoder struct {state int b byte T bytes. Buffer r io. Bytereader err Error M *element n string} func (d *decoder) getAttr (M *element, E String) string {for n: = M. Attr; Nil! = N; n = n.next {if E = = n.name {return N.value}} return ""} func (D *decoder) getelement (E string, a string) string {fo R N: = D.M; Nil! = N; n = n.next {if E = = n.element {return d.getattr (n, a)}} return ""} func (D *decoder) newattrnextcomment (value string {d.m.attr.comment = value println (value)} func (d *decoder) newattrnext (name string, value string) {Attr: = new (Attr ) attr. Name = Name attr. Value = value if nil = = d.m.attr {Attr.next = nil} else {attr.next = d.m.attr} d.m.attr = attr} func (d *decoder) newelement (name string) {element: = new (Element) element. element = name element. Attr = Nil if nil = = d.m {Element.next = nil} else {element.next = d.m} d.m = element} func (d *decoder) Switchtomap () {for {d.b, D.err = D.r.readbyte () if d.err! = nil {break} switch d.state {case stat_none:if d.b = ' [' {d.state = Stat_group} else if d.b = = '; ' {d.state = stat_comment} else if!unicode. IsSpace (Rune (d.b)) {d.state = Stat_key d.t.writebyte (Byte (d.b))} break case Stat_group:if d.b = '] ' {d.state = Stat_n One d.newelement (d.t.string ()) D.t.reset ()} else if!unicode. IsSpace (Rune (d.b)) {D.t.writebyte (Byte (d.b))} break case Stat_key:if d.b = ' = ' {d.state = Stat_value D.N = d.t.string () D.t.reset ()} else if!unicode. IsSpace (Rune (d.b)) {D.t.writebyte (Byte (d.b))} break case Stat_value:if!unicode. IsSpace (Rune (d.b)) {D.t.writebyte (Byte (d.b))} else {d.state = Stat_none d.newattrnext (D.N, d.t.string ()) D.t.reset ()} Break Case Stat_comment:If!unicode. IsSpace (Rune (d.b)) {D.t.writebyte (Byte (d.b))} else {d.state = Stat_none d.newattrnextcomment (d.t.string ()) D.t.reset ( )} Break Default:d.state = Stat_none Break}}} func (d *decoder) Switchtoreader (R io. Reader) {If RB, OK: = R. (IO. Bytereader); OK {D.R = rb} else {D.R = Bufio. Newreader (R)} d.switchtomap ()} func newdecoder (R io. Reader) *decoder {d: = &decoder{} d.switchtoreader (R) return D} func main () {xmlfile, err: = OS. Open ("Hh.ini") if nil! = Err {return} defer Xmlfile.close () d: = Newdecoder (xmlfile) println (d.getelement ("AAAA", "AC")) }