Beispiel #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)
		}
	}
}
Beispiel #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{}))
			}
		}
	}
}
Beispiel #3
0
func main() {
	values, err := x2j.ValuesFromTagPath(doc, "doc.some_tag.geoInfo.country.-name")
	if err != nil {
		fmt.Println("err:", err.Error())
	}
	for _, v := range values {
		fmt.Println("v:", v)
	}
}
Beispiel #4
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)
}
Beispiel #5
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")
}