forked from zpsean/go4api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scxml.go
66 lines (54 loc) · 1.42 KB
/
scxml.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
* go4api - an api testing tool written in Go
* Created by: Ping Zhu 2019
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
*/
package statechart
import (
"fmt"
// "time"
// "os"
// "sort"
"io"
"strings"
"encoding/xml"
)
// convert the scxml format to xstate
func XmlDecode (data []byte) {
decoder := xml.NewDecoder(strings.NewReader(string(data)))
// result := make(map[string]string)
// key := ""
for {
token, err := decoder.Token()
if err == io.EOF{
fmt.Println("parse Finish")
break
// return result
}
if err != nil{
fmt.Println("parse Fail:",err)
break
// return result
}
switch tp := token.(type) {
case xml.StartElement:
se := xml.StartElement(tp)
fmt.Println("se.Name:", se.Name)
fmt.Println("se.Attr:", se.Attr)
fmt.Println()
case xml.EndElement:
ee := xml.EndElement(tp)
fmt.Println("ee.Name:", ee.Name)
fmt.Println()
case xml.CharData:
// cd := xml.CharData(tp)
// data := string(cd)
// fmt.Println("cd.content:", data)
// fmt.Println()
}
}
}