Do not repeat xmlns in attributes on parsing

This commit is contained in:
Mickael Remond 2018-01-15 12:47:26 +01:00
parent dade3504f0
commit c821267928
No known key found for this signature in database
GPG key ID: E6F6045D79965AA3
2 changed files with 8 additions and 1 deletions

8
iq.go
View file

@ -166,7 +166,13 @@ type Node struct {
} }
func (n *Node) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error { func (n *Node) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
n.Attrs = start.Attr // Assign "n.Attrs = start.Attr", without repeating xmlns in attributes
for _, attr := range start.Attr {
// Do not repeat xmlns
if attr.Name.Local != "xmlns" {
n.Attrs = append(n.Attrs, attr)
}
}
type node Node type node Node
return d.DecodeElement((*node)(n), &start) return d.DecodeElement((*node)(n), &start)
} }

View file

@ -37,6 +37,7 @@ func TestGenerateIq(t *testing.T) {
}, },
Nodes: []Node{ Nodes: []Node{
{XMLName: xml.Name{ {XMLName: xml.Name{
Space: "http://jabber.org/protocol/disco#info",
Local: "identity", Local: "identity",
}, },
Attrs: []xml.Attr{ Attrs: []xml.Attr{