Skip to content

Commit 1d5a48e

Browse files
committed
fix #96, ignoring the prefix name output if its declaring the default namespace
1 parent 9dbfa11 commit 1d5a48e

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

parse.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,11 @@ func (p *parser) parse() (*Node, error) {
105105
p.prev = node
106106
}
107107
// https://www.w3.org/TR/xml-names/#scoping-defaulting
108+
var defaultNameSpace string
108109
for _, att := range tok.Attr {
109110
if att.Name.Local == "xmlns" {
110111
p.space2prefix[att.Value] = ""
112+
defaultNameSpace = att.Value
111113
} else if att.Name.Space == "xmlns" {
112114
p.space2prefix[att.Value] = att.Name.Local
113115
}
@@ -133,14 +135,17 @@ func (p *parser) parse() (*Node, error) {
133135
}
134136

135137
node := &Node{
136-
Type: ElementNode,
137-
Data: tok.Name.Local,
138-
Prefix: p.space2prefix[tok.Name.Space],
138+
Type: ElementNode,
139+
Data: tok.Name.Local,
140+
//Prefix: p.space2prefix[tok.Name.Space],
139141
NamespaceURI: tok.Name.Space,
140142
Attr: attributes,
141143
level: p.level,
142144
}
143-
145+
// https://github.com/antchfx/xmlquery/issues/96
146+
if !(tok.Name.Space == defaultNameSpace) {
147+
node.Prefix = p.space2prefix[tok.Name.Space]
148+
}
144149
if p.level == p.prev.level {
145150
AddSibling(p.prev, node)
146151
} else if p.level > p.prev.level {

0 commit comments

Comments
 (0)