func setAttr(xn *xmlx.Node, name, value string, onlySetIfEmpty bool) { for _, att := range xn.Attributes { if att.Name.Local == name { if (!onlySetIfEmpty) || (len(att.Value) == 0) { logFmt("\t\tsetAttr %s.%s = %s\n", xn.Name.Local, name, value) att.Value = value } return } } logFmt("\t\taddAttr %s.%s = %s\n", xn.Name.Local, name, value) att := &xmlx.Attr{Value: value} att.Name.Local = name xn.Attributes = append(xn.Attributes, att) }
func delAttr(xn *xmlx.Node, name string) { if Strict { pos := -1 for i, att := range xn.Attributes { if att.Name.Local == name { pos = i break } } if pos >= 0 { logFmt("\t\tdelAttr %s.%s\n", xn.Name.Local, name) nuAtts := append(xn.Attributes[:pos], xn.Attributes[pos+1:]...) xn.Attributes = nuAtts } } }