From d59371c359a0e11571e09d0cf597dea8fb48cfd7 Mon Sep 17 00:00:00 2001 From: Matthew Kanwisher Date: Thu, 29 Aug 2013 17:29:22 -0400 Subject: [PATCH 1/3] add some new helper methods --- node.go | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/node.go b/node.go index b451e15..c57dee7 100644 --- a/node.go +++ b/node.go @@ -27,7 +27,7 @@ var IndentPrefix = "" type Attr struct { Name xml.Name // Attribute namespace and name. - Value string // Attribute value. + Value string // Attribute value. } type Node struct { @@ -395,6 +395,26 @@ func rec_SelectNodes(cn *Node, namespace, name string, list *[]*Node, recurse bo } } +func (this *Node) RemoveNameSpace() { + this.Name.Space = "" +} + +func (this *Node) SetAttr(name, value string) { + for _, v := range this.Attributes { + if name == v.Name.Local { + v.Value = value + return + } + } + //Add + attr := new(Attr) + attr.Name.Local = name + attr.Name.Space = "" + attr.Value = value + this.Attributes = append(this.Attributes, attr) + return +} + // Convert node to appropriate []byte representation based on it's @Type. // Note that NT_ROOT is a special-case empty node used as the root for a // Document. This one has no representation by itself. It merely forwards the From 3236d1c7cbfadc08f45ff54c967ac501f7874369 Mon Sep 17 00:00:00 2001 From: Matthew Kanwisher Date: Thu, 29 Aug 2013 17:38:55 -0400 Subject: [PATCH 2/3] more helper methods --- node.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/node.go b/node.go index c57dee7..42d55f7 100644 --- a/node.go +++ b/node.go @@ -397,6 +397,16 @@ func rec_SelectNodes(cn *Node, namespace, name string, list *[]*Node, recurse bo func (this *Node) RemoveNameSpace() { this.Name.Space = "" + this.RemoveAttr("xmlns") +} + +func (this *Node) RemoveAttr(name string) { + for i, v := range this.Attributes { + if name == v.Name.Local { + //Delete it + this.Attributes = append(this.Attributes[:i], this.Attributes[i+1:]...) + } + } } func (this *Node) SetAttr(name, value string) { From 199b36f2345692f9280b65ccc20fed1617927c15 Mon Sep 17 00:00:00 2001 From: Matthew Kanwisher Date: Thu, 29 Aug 2013 18:19:26 -0400 Subject: [PATCH 3/3] cleaning up remove function --- node.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/node.go b/node.go index 42d55f7..85e4542 100644 --- a/node.go +++ b/node.go @@ -397,7 +397,11 @@ func rec_SelectNodes(cn *Node, namespace, name string, list *[]*Node, recurse bo func (this *Node) RemoveNameSpace() { this.Name.Space = "" - this.RemoveAttr("xmlns") + // this.RemoveAttr("xmlns") //This is questionable + + for _, v := range this.Children { + v.RemoveNameSpace() + } } func (this *Node) RemoveAttr(name string) {