Skip to content

Commit f9093e1

Browse files
committed
fix #106
1 parent 36d86a4 commit f9093e1

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

parse.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -343,10 +343,11 @@ func (p *parser) parse() (*Node, error) {
343343
AddSibling(p.prev.Parent, node)
344344
}
345345
case xml.ProcInst: // Processing Instruction
346-
if !(p.prev.Type == DeclarationNode || p.prev.Type == ProcessingInstruction) {
347-
p.level++
346+
level := p.level
347+
if p.prev.Type != ElementNode && p.prev.Type != DeclarationNode && p.prev.Type != ProcessingInstruction {
348+
level = p.level + 1
348349
}
349-
node := &Node{Type: DeclarationNode, Data: tok.Target, level: p.level, LineNumber: p.currentLine}
350+
node := &Node{Type: DeclarationNode, Data: tok.Target, level: level, LineNumber: p.currentLine}
350351
pairs := strings.Split(string(tok.Inst), " ")
351352
for _, pair := range pairs {
352353
pair = strings.TrimSpace(pair)
@@ -358,17 +359,18 @@ func (p *parser) parse() (*Node, error) {
358359
node.Type = ProcessingInstruction
359360
node.ProcInst = &ProcInstData{Target: tok.Target, Inst: strings.TrimSpace(string(tok.Inst))}
360361
}
361-
if p.level == p.prev.level {
362+
if level == p.prev.level {
362363
AddSibling(p.prev, node)
363-
} else if p.level > p.prev.level {
364+
} else if level > p.prev.level {
364365
AddChild(p.prev, node)
365-
} else if p.level < p.prev.level {
366-
for i := p.prev.level - p.level; i > 1; i-- {
366+
} else if level < p.prev.level {
367+
for i := p.prev.level - level; i > 1; i-- {
367368
p.prev = p.prev.Parent
368369
}
369370
AddSibling(p.prev.Parent, node)
370371
}
371372
p.prev = node
373+
p.level = level
372374
case xml.Directive:
373375
node := &Node{Type: NotationNode, Data: string(tok), level: p.level, LineNumber: p.currentLine}
374376
if p.level == p.prev.level {

0 commit comments

Comments
 (0)