Skip to content
This repository has been archived by the owner on Jun 7, 2019. It is now read-only.

Commit

Permalink
Defining multiple attributes list is possible
Browse files Browse the repository at this point in the history
E.g. for nodes and edges at the same time
  • Loading branch information
mvdan committed Sep 17, 2015
1 parent 23fa37f commit b327010
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 22 deletions.
8 changes: 4 additions & 4 deletions gexf.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ type Graph struct {
IDType IDType `xml:"idtype,attr,omitempty"`
DefEdge EdgeType `xml:"defaultedgetype,attr,omitempty"`

Attrs *Attributes `xml:"attributes,omitempty"`
Nodes *[]Node `xml:"nodes>node,omitempty"`
Edges *[]Edge `xml:"edges>edge,omitempty"`
Attrs []ClassAttrs `xml:"attributes,omitempty"`
Nodes *[]Node `xml:"nodes>node,omitempty"`
Edges *[]Edge `xml:"edges>edge,omitempty"`
}

type EdgeType int
Expand Down Expand Up @@ -156,7 +156,7 @@ func (t ClassType) MarshalText() ([]byte, error) {
return []byte(t.String()), nil
}

type Attributes struct {
type ClassAttrs struct {
Class ClassType `xml:"class,attr"`
Attrs []Attr `xml:"attribute"`
}
Expand Down
38 changes: 20 additions & 18 deletions gexf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,24 +112,26 @@ func TestAttributes(t *testing.T) {
}
doc.Graph = Graph{
DefEdge: Directed,
Attrs: &Attributes{
Class: ClassNode,
Attrs: []Attr{
{
ID: "0",
Title: "url",
Type: "string",
},
{
ID: "1",
Title: "indegree",
Type: "float",
},
{
ID: "2",
Title: "frog",
Type: "boolean",
Default: "true",
Attrs: []ClassAttrs{
{
Class: ClassNode,
Attrs: []Attr{
{
ID: "0",
Title: "url",
Type: "string",
},
{
ID: "1",
Title: "indegree",
Type: "float",
},
{
ID: "2",
Title: "frog",
Type: "boolean",
Default: "true",
},
},
},
},
Expand Down

0 comments on commit b327010

Please sign in to comment.