func firstByName(root dom.Element, name string) (ret dom.Element) { for _, x := range root.Children() { if e, ok := x.(dom.Element); ok && e.Name() == name { ret = e break } } return }
func (x *domm) Unmarshal() (err error) { d := xml.NewDecoder(x.buf) var _t xml.Token var this dom.Element for stop := false; !stop && err == nil; { if _t, err = d.RawToken(); err == nil { switch t := _t.(type) { case xml.StartElement: el := dom.Elem(dom.ThisName(t.Name)) if x.model == nil { x.model = el this = el } else { this.AppendChild(el) this = el } for _, a := range t.Attr { this.Attr(dom.ThisName(a.Name), a.Value) } case xml.CharData: if this != nil { this.AppendChild(dom.Txt(string(t))) } else { stop = true } case xml.EndElement: if this != nil { if p := this.Parent(); p != nil { this = p.(dom.Element) } else { stop = true } } else { stop = true } case nil: default: halt.As(100, reflect.TypeOf(t)) } } } return }