diff --git a/examples/leafnodes.go b/examples/leafnodes.go index 38c433c..e362184 100644 --- a/examples/leafnodes.go +++ b/examples/leafnodes.go @@ -4,7 +4,6 @@ package main import ( "fmt" - "strings" "github.com/clbanning/mxj" ) @@ -46,13 +45,10 @@ func main() { fmt.Println("err:", err) return } + mxj.LeafUseDotNotation() l := m.LeafNodes() - - // now change the [n] to .n for _, v := range l { - p := strings.Replace(v.Path, "[", ".", -1) - p = strings.Replace(p, "]", "", -1) - fmt.Println("path:", p, "value:", v.Value) + fmt.Println("path:", v.Path, "value:", v.Value) } /* Output (sequence not guaranteed): diff --git a/leafnode.go b/leafnode.go index bea19c5..cf413eb 100644 --- a/leafnode.go +++ b/leafnode.go @@ -24,9 +24,13 @@ type LeafNode struct { // LeafNodes - returns an array of all LeafNode values for the Map. // The option no_attr argument suppresses attribute values (keys with prepended hyphen, '-') // as well as the "#text" key for the associated simple element value. -// NOTE: if PrependAttrWithHypen(false), then #test is stripping "#text" key -// will result in attributes having .attr-name as terminal node in 'path' while -// the path for the element value, itself, will be the base path w/o "#text". +// +// PrependAttrWithHypen(false) will result in attributes having .attr-name as +// terminal node in 'path' while the path for the element value, itself, will be +// the base path w/o "#text". +// +// LeafUseDotNotation(true) causes list members to be identified using ".N" syntax +// rather than "[N]" syntax. func (mv Map) LeafNodes(no_attr ...bool) []LeafNode { var a bool if len(no_attr) == 1 {