From c821267928a2b9adf974c9b8e758cd1f5a1f8c0a Mon Sep 17 00:00:00 2001 From: Mickael Remond Date: Mon, 15 Jan 2018 12:47:26 +0100 Subject: [PATCH] Do not repeat xmlns in attributes on parsing --- iq.go | 8 +++++++- iq_test.go | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/iq.go b/iq.go index a34a919..1b174f6 100644 --- a/iq.go +++ b/iq.go @@ -166,7 +166,13 @@ type Node struct { } 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 return d.DecodeElement((*node)(n), &start) } diff --git a/iq_test.go b/iq_test.go index 1eba656..ab85370 100644 --- a/iq_test.go +++ b/iq_test.go @@ -37,6 +37,7 @@ func TestGenerateIq(t *testing.T) { }, Nodes: []Node{ {XMLName: xml.Name{ + Space: "http://jabber.org/protocol/disco#info", Local: "identity", }, Attrs: []xml.Attr{