Add xml attribute support for XMLElement (#136)

* Save attributes of the xml element

* Update unittest to check xml attributes
This commit is contained in:
milampi 2022-05-13 11:24:06 +03:00 committed by GitHub
parent 99ddfc1aa4
commit 1411b9cc8b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 0 deletions

View File

@ -1009,6 +1009,7 @@ func (m *clientMessage) OtherStrings() []string {
type XMLElement struct { type XMLElement struct {
XMLName xml.Name XMLName xml.Name
Attr []xml.Attr `xml:",any,attr"` // Save the attributes of the xml element
InnerXML string `xml:",innerxml"` InnerXML string `xml:",innerxml"`
} }

View File

@ -87,10 +87,12 @@ func TestStanzaError(t *testing.T) {
OtherElem: []XMLElement{ OtherElem: []XMLElement{
XMLElement{ XMLElement{
XMLName: xml.Name{Space: "google:mobile:data", Local: "gcm"}, XMLName: xml.Name{Space: "google:mobile:data", Local: "gcm"},
Attr: []xml.Attr{xml.Attr{Name:xml.Name{Space:"", Local:"xmlns"}, Value:"google:mobile:data"}},
InnerXML: "\n\t\t{\"random\": \"<text>\"}\n\t", InnerXML: "\n\t\t{\"random\": \"<text>\"}\n\t",
}, },
XMLElement{ XMLElement{
XMLName: xml.Name{Space: "jabber:client", Local: "error"}, XMLName: xml.Name{Space: "jabber:client", Local: "error"},
Attr: []xml.Attr{xml.Attr{Name:xml.Name{Space:"", Local:"code"}, Value:"400"},xml.Attr{Name:xml.Name{Space:"", Local:"type"}, Value:"modify"}},
InnerXML: ` InnerXML: `
<bad-request xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/> <bad-request xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/>
<text xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"> <text xmlns="urn:ietf:params:xml:ns:xmpp-stanzas">