...
1
2
3 package mxj
4
5 import (
6 "fmt"
7 "testing"
8 )
9
10 func TestXml3(t *testing.T) {
11 fmt.Println("\n------------ xml3_test.go")
12 }
13
14
15 func TestOnlyAttributes(t *testing.T) {
16 fmt.Println("========== TestOnlyAttributes")
17 dom, err := NewMapXml([]byte(`
18 <memballoon model="virtio">
19 <address type="pci" domain="0x0000" bus="0x00" slot="0x05" function="0x0"/>
20 <empty/>
21 </memballoon>)`))
22 if err != nil {
23 t.Fatal(err)
24 }
25 xml, err := dom.XmlIndent("", " ")
26 if err != nil {
27 t.Fatal(err)
28 }
29 fmt.Println(string(xml))
30 }
31
32 func TestOnlyAttributesSeq(t *testing.T) {
33 fmt.Println("========== TestOnlyAttributesSeq")
34 dom, err := NewMapXmlSeq([]byte(`
35 <memballoon model="virtio">
36 <address type="pci" domain="0x0000" bus="0x00" slot="0x05" function="0x0"/>
37 <empty/>
38 </memballoon>)`))
39 if err != nil {
40 t.Fatal(err)
41 }
42 xml, err := dom.XmlIndent("", " ")
43 if err != nil {
44 t.Fatal(err)
45 }
46 fmt.Println(string(xml))
47 }
48
49 func TestDecodeSimpleValuesAsMap(t *testing.T) {
50 fmt.Println("========== TestDecodeSimpleValuesAsMap")
51 DecodeSimpleValuesAsMap()
52
53 xml := `<item>
54 <id>30102</id>
55 <title>Mini Drone Inteligente - Branco</title>
56 <price unit="BRL">149.90</price>
57 </item>`
58 m, err := NewMapXml([]byte(xml))
59 if err != nil {
60 t.Fatal(err)
61 }
62 fmt.Println("xml:", string(xml))
63 fmt.Printf("m : %v\n", m)
64
65 fmt.Println("========== (default)")
66 DecodeSimpleValuesAsMap()
67 m, err = NewMapXml([]byte(xml))
68 if err != nil {
69 t.Fatal(err)
70 }
71 fmt.Printf("m : %v\n", m)
72 }
73
View as plain text