File: xmlnode.go

package info (click to toggle)
golang-github-christrenkamp-goxpath 1.0~alpha3%2Bgit20170922.c385f95-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 308 kB
  • sloc: sh: 16; makefile: 3; xml: 3
file content (47 lines) | stat: -rw-r--r-- 852 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package xmlstruct

import (
	"encoding/xml"
	"fmt"
	"reflect"

	"github.com/ChrisTrenkamp/goxpath/tree"
)

type XMLNode struct {
	Val      reflect.Value
	pos      int
	prnt     tree.Elem
	nodeType tree.NodeType
	prntTag  string
}

func (x *XMLNode) ResValue() string {
	if x.Val.Kind() == reflect.Ptr {
		return fmt.Sprintf("%v", x.Val.Elem().Interface())
	}
	return fmt.Sprintf("%v", x.Val.Interface())
}

func (x *XMLNode) Pos() int {
	return x.pos
}

func (x *XMLNode) GetToken() xml.Token {
	switch x.nodeType {
	case tree.NtAttr:
		return xml.Attr{Name: getTagInfo(x.prntTag).name, Value: x.ResValue()}
	case tree.NtChd:
		return xml.CharData(x.ResValue())
	}
	//case tree.NtComm:
	return xml.Comment(x.ResValue())
}

func (x *XMLNode) GetParent() tree.Elem {
	return x.prnt
}

func (x *XMLNode) GetNodeType() tree.NodeType {
	return x.nodeType
}