main
c49a4ab ยท 23 days ago 6 commits
 1package internal
 2
 3// Document.xml (schema version 1.4, as produced by circuit-diagram.org).
 4type xmlCircuit struct {
 5	Version    string         `xml:"version,attr"`
 6	Adds       []xmlAdd       `xml:"definitions>src>add"`
 7	Components []xmlComponent `xml:"elements>c"`
 8}
 9
10type xmlAdd struct {
11	ID   string `xml:"id,attr"`
12	Item string `xml:"item,attr"`
13}
14
15type xmlComponent struct {
16	ID           string    `xml:"id,attr"`
17	DefinitionID string    `xml:"tp,attr"` // references xmlAdd.ID, formatted as "{N}"
18	Props        []xmlProp `xml:"prs>p"`
19	Conns        []xmlConn `xml:"cns>cn"`
20}
21
22type xmlProp struct {
23	Key   string `xml:"k,attr"`
24	Value string `xml:"v,attr"`
25}
26
27type xmlConn struct {
28	ID  string `xml:"id,attr"`
29	Pin string `xml:"pt,attr"`
30}
31
32func (c xmlComponent) prop(key string) (string, bool) {
33	for _, p := range c.Props {
34		if p.Key == key {
35			return p.Value, true
36		}
37	}
38	return "", false
39}