Ejemplo n.º 1
0
func main() {
	var docs = []string{doc1, doc2}

	for n, doc := range docs {
		fmt.Println("\nTestValuesFromTagPath2(), iteration:", n, "\n", doc)

		m, _ := x2j.DocToMap(doc)
		fmt.Println("map:", x2j.WriteMap(m))

		v, _ := x2j.ValuesFromTagPath(doc, "data.*")
		fmt.Println("\npath == data.*: len(v):", len(v))
		for key, val := range v {
			fmt.Println(key, ":", val)
		}
		mm := v[0]
		for key, val := range mm.(map[string]interface{}) {
			fmt.Println(key, ":", val)
		}

		v, _ = x2j.ValuesFromTagPath(doc, "data.*.*")
		fmt.Println("\npath == data.*.*: len(v):", len(v))
		for key, val := range v {
			fmt.Println(key, ":", val)
		}
	}
}
Ejemplo n.º 2
0
// Parse returns a ConfigContainer with parsed xml config map.
func (xc *Config) Parse(filename string) (tconfig.Configer, error) {
	file, err := os.Open(filename)
	if err != nil {
		return nil, err
	}
	defer file.Close()

	x := &ConfigContainer{data: make(map[string]interface{})}
	content, err := ioutil.ReadAll(file)
	if err != nil {
		return nil, err
	}

	d, err := x2j.DocToMap(string(content))
	if err != nil {
		return nil, err
	}

	x.data = d["config"].(map[string]interface{})
	return x, nil
}