-
Notifications
You must be signed in to change notification settings - Fork 0
/
diaxml.go
123 lines (109 loc) · 2.63 KB
/
diaxml.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package main
import (
"bytes"
"encoding/xml"
"fmt"
"io"
"io/ioutil"
)
type Composite struct {
XMLName xml.Name `xml:"attribute"`
Attributes []Attribute
}
type Color struct {
XMLName xml.Name `xml:"color"`
Val string `xml:"val,attr"`
}
type Point struct {
XMLName xml.Name `xml:"point"`
Val string `xml:"val,attr"`
}
type Real struct {
XMLName xml.Name `xml:"real"`
Val float64 `xml:"val,attr"`
}
type Rectangle struct {
XMLName xml.Name `xml:"rectangle"`
Val string `xml:"val,attr"`
}
type Attribute struct {
XMLName xml.Name `xml:"attribute"`
Name string `xml:"name,attr"`
Color Color
Point Point
Real Real
String string `xml:"string"`
Rectangle Rectangle
Composite Composite
}
type Object struct {
XMLName xml.Name `xml:"object"`
ID string `xml:"id,attr"`
Attribute []Attribute `xml:"attribute"`
}
type Layer struct {
XMLName xml.Name `xml:"layer"`
Object []Object `xml:"object"`
}
type Dia struct {
XMLName xml.Name `xml:"diagram"`
Layer Layer
}
type Current struct {
obj_pos string
obj_bb string
elem_corner string
elem_width float64
elem_height float64
fill_color string
text_color string
line_color string
}
var currentData map[string]*Current
func parseXML(br io.Reader) {
b, _ := ioutil.ReadAll(br)
var dia Dia
err := xml.Unmarshal(b, &dia)
if err != nil {
fmt.Println(err)
}
// Build storage for existing locations. color, etc.
currentData = make(map[string]*Current)
for _, obj := range dia.Layer.Object {
var name string
current := &Current{}
for _, attr := range obj.Attribute {
if attr.Name == "name" {
name = attr.String[1 : len(attr.String)-1]
} else if attr.Name == "stereotype" {
name = attr.String[1:len(attr.String)-1] + "." + name
} else if attr.Name == "obj_pos" {
current.obj_pos = attr.Point.Val
} else if attr.Name == "obj_bb" {
current.obj_bb = attr.Rectangle.Val
} else if attr.Name == "elem_corner" {
current.elem_corner = attr.Point.Val
} else if attr.Name == "elem_width" {
current.elem_width = attr.Real.Val
} else if attr.Name == "elem_height" {
current.elem_height = attr.Real.Val
} else if attr.Name == "line_color" {
current.line_color = attr.Color.Val
} else if attr.Name == "text_color" {
current.text_color = attr.Color.Val
} else if attr.Name == "fill_color" {
current.fill_color = attr.Color.Val
}
}
if len(name) == 0 {
continue
}
//fmt.Printf("%s = %v\n", name, current)
currentData[name] = current
}
}
func escape(in string) string {
s := bytes.NewBufferString("")
xml.EscapeText(s, []byte(in))
return s.String()
}