Put the sub-elements of Message and Presence into the jabber:client namespace.
--- a/structs.go Fri Dec 28 17:07:20 2012 -0700
+++ b/structs.go Fri Dec 28 17:56:13 2012 -0700
@@ -96,11 +96,11 @@
// message stanza
type Message struct {
- XMLName xml.Name `xml:"message"`
+ XMLName xml.Name `xml:"jabber:client message"`
Header
- Subject *Generic `xml:"subject"`
- Body *Generic `xml:"body"`
- Thread *Generic `xml:"thread"`
+ Subject *Generic `xml:"jabber:client subject"`
+ Body *Generic `xml:"jabber:client body"`
+ Thread *Generic `xml:"jabber:client thread"`
}
var _ Stanza = &Message{}
@@ -108,9 +108,9 @@
type Presence struct {
XMLName xml.Name `xml:"presence"`
Header
- Show *Generic `xml:"show"`
- Status *Generic `xml:"status"`
- Priority *Generic `xml:"priority"`
+ Show *Generic `xml:"jabber:client show"`
+ Status *Generic `xml:"jabber:client status"`
+ Priority *Generic `xml:"jabber:client priority"`
}
var _ Stanza = &Presence{}
--- a/structs_test.go Fri Dec 28 17:07:20 2012 -0700
+++ b/structs_test.go Fri Dec 28 17:56:13 2012 -0700
@@ -9,7 +9,9 @@
"encoding/xml"
"fmt"
"os"
+ "reflect"
"runtime"
+ "strings"
"testing"
)
@@ -112,6 +114,30 @@
func TestMarshalEscaping(t *testing.T) {
msg := &Message{Body: &Generic{XMLName: xml.Name{Local: "body"},
Chardata: `&<!-- "`}}
- exp := `<message><body>&<!-- "</body></message>`
+ exp := `<message xmlns="jabber:client"><body>&<!-- "</body></message>`
assertMarshal(t, exp, msg)
}
+
+func TestUnmarshalMessage(t *testing.T) {
+ str := `<message to="a@b.c"><body>foo!</body></message>`
+ r := strings.NewReader(str)
+ ch := make(chan interface{})
+ go readXml(r, ch, make(map[string]func(*xml.Name) interface{}))
+ obs := <-ch
+ exp := &Message{XMLName: xml.Name{Local: "message", Space: "jabber:client"},
+ Header: Header{To:"a@b.c", Innerxml: "<body>foo!</body>"},
+ Body: &Generic{XMLName: xml.Name{Local: "body", Space: "jabber:client"},
+ Chardata: "foo!"}}
+ if !reflect.DeepEqual(obs, exp) {
+ t.Errorf("read %s\ngot: %#v\nwant: %#v\n", str, obs, exp)
+ }
+ obsMsg, ok := obs.(*Message)
+ if !ok {
+ t.Fatalf("Not a Message: %T", obs)
+ }
+ obsBody := obsMsg.Body
+ expBody := exp.Body
+ if !reflect.DeepEqual(obsBody, expBody) {
+ t.Errorf("body\ngot: %#v\nwant: %#v\n", obsBody, expBody)
+ }
+}