-
Notifications
You must be signed in to change notification settings - Fork 0
/
xmlpath.go
41 lines (32 loc) · 978 Bytes
/
xmlpath.go
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
package epplib
import (
"fmt"
"strings"
)
// XMLPathBuilder is a string with xml path functions.
type XMLPathBuilder string
// NewXMLPathBuilder get a new xml path builder.
func NewXMLPathBuilder() XMLPathBuilder {
return ""
}
// AddOrphan add an orphaned (no parent - no "/" prefix) tag to the path.
func (b XMLPathBuilder) AddOrphan(tag, namespace string) XMLPathBuilder {
if namespace != "" {
tag = fmt.Sprintf("%s[namespace-uri()='%s']", tag, namespace)
}
return XMLPathBuilder(string(b) + tag)
}
// Add a tag to the path. If no "/" is present in the beginning of the tag it will be added.
func (b XMLPathBuilder) Add(tag, namespace string) XMLPathBuilder {
if !strings.HasPrefix(tag, "/") {
tag = fmt.Sprintf("/%s", tag)
}
if namespace != "" {
tag = fmt.Sprintf("%s[namespace-uri()='%s']", tag, namespace)
}
return XMLPathBuilder(string(b) + tag)
}
// String get the path as a string.
func (b XMLPathBuilder) String() string {
return string(b)
}