gexf12: fix omitable and unbounded attributes
MODIFY
graph/formats/gexf12/gexf.go
graph/formats/gexf12/gexf.go
@@ -61,7 +61,7 @@ func (t *Meta) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
// Graph stores the graph nodes, edges, dynamics and visualization data.
type Graph struct {
- Attributes *Attributes `xml:"attributes"`
+ Attributes []Attributes `xml:"attributes"`
Nodes Nodes `xml:"nodes"`
Edges Edges `xml:"edges"`
// TimeFormat may be one of "integer", "double", "date" or "dateTime".
@@ -71,11 +71,11 @@ type Graph struct {
End *string `xml:"end,attr,omitempty"`
Endopen *string `xml:"endopen,attr,omitempty"`
// DefaultEdgeType may be one of "directed", "undirected" or "mutual".
- DefaultEdgeType string `xml:"defaultedgetype,attr,omitempty"`
+ DefaultEdgeType *string `xml:"defaultedgetype,attr,omitempty"`
// IDType may be one of "integer" or "string".
- IDType string `xml:"idtype,attr,omitempty"`
+ IDType *string `xml:"idtype,attr,omitempty"`
// Mode may be "static" or "dynamic".
- Mode string `xml:"mode,attr,omitempty"`
+ Mode *string `xml:"mode,attr,omitempty"`
}
// Attributes holds a collection of potentially dynamic attributes
@@ -99,8 +99,8 @@ type Attribute struct {
// Type may be one of "integer", "long", "double", "float",
// "boolean", "liststring", "string", or "anyURI".
Type string `xml:"type,attr"`
- Default *string `xml:"default"`
- Options *string `xml:"options"`
+ Default *string `xml:"default,omitempty"`
+ Options *string `xml:"options,omitempty"`
}
// Nodes holds a collection of nodes constituting a graph or subgraph.

MODIFY
graph/formats/gexf12/gexf_test.go
graph/formats/gexf12/gexf_test.go
@@ -39,8 +39,8 @@ var gexfExampleTests = []struct {
{ID: "0", Source: "0", Target: "1"},
},
},
- DefaultEdgeType: "directed",
- Mode: "static",
+ DefaultEdgeType: stringPtr("directed"),
+ Mode: stringPtr("static"),
},
Version: "1.2",
},
@@ -66,7 +66,7 @@ var gexfExampleTests = []struct {
LastModified: time.Date(2009, 03, 20, 0, 0, 0, 0, time.UTC),
},
Graph: Graph{
- Attributes: &Attributes{
+ Attributes: []Attributes{{
Class: "node",
Attributes: []Attribute{
{
@@ -86,7 +86,7 @@ var gexfExampleTests = []struct {
Default: stringPtr("true"),
},
},
- },
+ }},
Nodes: Nodes{
Nodes: []Node{
{
@@ -129,7 +129,7 @@ var gexfExampleTests = []struct {
{ID: "4", Source: "0", Target: "3"},
},
},
- DefaultEdgeType: "directed",
+ DefaultEdgeType: stringPtr("directed"),
},
Version: "1.2",
},
@@ -239,8 +239,8 @@ var gexfExampleTests = []struct {
{ID: "8", Source: "a", Target: "j"},
},
},
- DefaultEdgeType: "directed",
- Mode: "static",
+ DefaultEdgeType: stringPtr("directed"),
+ Mode: stringPtr("static"),
},
Version: "1.2",
},
@@ -315,8 +315,8 @@ var gexfExampleTests = []struct {
{ID: "3", Source: "f", Target: "a"},
},
},
- DefaultEdgeType: "directed",
- Mode: "static",
+ DefaultEdgeType: stringPtr("directed"),
+ Mode: stringPtr("static"),
},
Version: "1.2",
},

gexf12: fix omitable and unbounded attributes