Exemplo 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)
		}
	}
}
Exemplo n.º 2
0
func fullPath(docs []string) {
	for i, doc := range docs {
		fmt.Println("\ndoc:", i)
		fmt.Println(doc)
		path := "Envelope.Body.GetClaimStatusCodesResponse.GetClaimStatusCodesResult.ClaimStatusCodeRecord"
		av, err := x2j.ValuesFromTagPath(doc, path)
		if err != nil {
			fmt.Println("err:", err.Error())
			return
		}
		if av == nil {
			fmt.Println("path:", path)
			fmt.Println("No ClaimStatusCodesResult code records.")
			continue
		}
		fmt.Println("\nPath:", path)
		fmt.Println("Number of code records:", len(av))
		fmt.Println("av:", av, "\n")
		for _, v := range av {
			switch v.(type) {
			case map[string]interface{}:
				fmt.Println("map[string]interface{}:", v.(map[string]interface{}))
			case []map[string]interface{}:
				fmt.Println("[]map[string]interface{}:", v.([]map[string]interface{}))
			case []interface{}:
				fmt.Println("[]interface{}:", v.([]interface{}))
			case interface{}:
				fmt.Println("interface{}:", v.(interface{}))
			}
		}
	}
}
Exemplo n.º 3
0
func main() {
	fmt.Println(doc)

	v, _ := x2j.ValuesFromTagPath(doc, "books")
	fmt.Println("path: books; len(v):", len(v))
	fmt.Printf("%+v\n\n", v)

	v, _ = x2j.ValuesFromTagPath(doc, "books.book")
	fmt.Println("path: books.book; len(v):", len(v))
	fmt.Printf("%+v\n\n", v)

	v, _ = x2j.ValuesFromTagPath(doc, "books.*")
	fmt.Println("path: books.*; len(v):", len(v))
	fmt.Printf("%+v\n\n", v)

	v, _ = x2j.ValuesFromTagPath(doc, "books.*.title")
	fmt.Println("path: books.*.title len(v):", len(v))
	fmt.Printf("%+v\n\n", v)

	v, _ = x2j.ValuesFromTagPath(doc, "books.*.*")
	fmt.Println("path: books.*.*; len(v):", len(v))
	fmt.Printf("%+v\n\n", v)
}
Exemplo n.º 4
0
func partPath1(doc string) {
	path := "Envelope.Body.*.*.ClaimStatusCodeRecord"
	av, err := x2j.ValuesFromTagPath(doc, path)
	if err != nil {
		fmt.Println("err:", err.Error())
		return
	}
	if av == nil {
		fmt.Println("path:", path)
		fmt.Println("No ClaimStatusCodesResult code records.")
		return
	}
	fmt.Println("\nPath:", path)
	fmt.Println("Number of code records:", len(av))
	fmt.Println("av:", av, "\n")
}