diff -r faef59c8db05 -r 8e425e340ca1 structs.go --- a/structs.go Sat Dec 24 13:11:36 2011 -0700 +++ b/structs.go Sun Dec 25 18:46:13 2011 -0700 @@ -38,17 +38,19 @@ // XMPP's XML element type Stream struct { - to string `xml:"attr"` - from string `xml:"attr"` - id string `xml:"attr"` - lang string `xml:"attr"` - version string `xml:"attr"` + To string `xml:"attr"` + From string `xml:"attr"` + Id string `xml:"attr"` + Lang string `xml:"attr"` + Version string `xml:"attr"` } var _ xml.Marshaler = &Stream{} +var _ fmt.Stringer = &Stream{} +// type StreamError struct { - cond definedCondition - text *errText + Any definedCondition + Text *errText } var _ xml.Marshaler = &StreamError{} @@ -58,8 +60,8 @@ } type errText struct { - Lang string - text string `xml:"chardata"` + Lang string `xml:"attr"` + Text string `xml:"chardata"` } var _ xml.Marshaler = &errText{} @@ -101,31 +103,37 @@ func (s *Stream) MarshalXML() ([]byte, os.Error) { buf := bytes.NewBuffer(nil) buf.WriteString("") // We never write return buf.Bytes(), nil } +func (s *Stream) String() string { + result, _ := s.MarshalXML() + return string(result) +} + func parseStream(se xml.StartElement) (*Stream, os.Error) { s := &Stream{} - se = se.Copy() for _, attr := range se.Attr { switch strings.ToLower(attr.Name.Local) { case "to": - s.to = attr.Value + s.To = attr.Value case "from": - s.from = attr.Value + s.From = attr.Value case "id": - s.id = attr.Value + s.Id = attr.Value case "lang": - s.lang = attr.Value + s.Lang = attr.Value case "version": - s.version = attr.Value + s.Version = attr.Value } } return s, nil @@ -134,9 +142,9 @@ func (s *StreamError) MarshalXML() ([]byte, os.Error) { buf := bytes.NewBuffer(nil) buf.WriteString("") - xml.Marshal(buf, s.cond) - if s.text != nil { - xml.Marshal(buf, s.text) + xml.Marshal(buf, s.Any) + if s.Text != nil { + xml.Marshal(buf, s.Text) } buf.WriteString("") return buf.Bytes(), nil @@ -148,7 +156,7 @@ writeField(buf, "xmlns", nsStreams) writeField(buf, "xml:lang", e.Lang) buf.WriteString(">") - xml.Escape(buf, []byte(e.text)) + xml.Escape(buf, []byte(e.Text)) buf.WriteString("") return buf.Bytes(), nil }