# `Yog.IO.GEXF`
[🔗](https://github.com/code-shoily/yog_ex/blob/v1.0.0/lib/yog/io/gexf.ex#L1)

GEXF (Graph Exchange XML Format) serialization support.

Provides functions to serialize and deserialize graphs in GEXF format,
the native format of [Gephi](https://gephi.org/) and supported by
many other graph visualization tools.

GEXF is an XML-based format that supports:
- **Nodes** with typed attributes
- **Edges** with typed attributes and weights
- **Directed and undirected** graphs
- **Visual attributes** (viz namespace): color, size, position
- **Dynamic graphs** (not yet supported)

## Performance

Uses Saxy for fast streaming SAX parsing when available (same as GraphML).
Falls back to `:xmerl` otherwise.

# `default_options`

```elixir
@spec default_options() :: tuple()
```

Returns default GEXF serialization options.

The options control data formatting:
- **node_formatter:** Function to convert node IDs to strings (default: `safe_string/1`)
- **edge_formatter:** Function to convert edge IDs to strings (default: `safe_string/1`)

Time complexity: $\mathcal{O}(1)$

# `deserialize`

```elixir
@spec deserialize(String.t()) :: {:ok, Yog.graph()} | {:error, term()}
```

Deserializes a GEXF string to a graph using default conversion.

Raises `ArgumentError` if xml is not a binary string.

Time complexity: $\mathcal{O}(V + E)$

# `deserialize_with`

```elixir
@spec deserialize_with((map() -&gt; any()), (map() -&gt; any()), String.t()) ::
  {:ok, Yog.graph()} | {:error, term()}
```

Deserializes a GEXF string into a graph with custom data mappers.

Raises `ArgumentError` if xml or data mappers are invalid.

Time complexity: $\mathcal{O}(V + E)$

# `options_with`

```elixir
@spec options_with((any() -&gt; any()), (any() -&gt; any())) :: tuple()
```

Creates GEXF options with custom formatters.

Raises `ArgumentError` if formatters are invalid.

Time complexity: $\mathcal{O}(1)$

# `read`

```elixir
@spec read(String.t()) :: {:ok, Yog.graph()} | {:error, term()}
```

Reads a graph from a GEXF file using default conversion.

Raises `ArgumentError` if path is not a binary string.

Time complexity: $\mathcal{O}(V + E)$ + file I/O

# `read_with`

```elixir
@spec read_with(String.t(), (map() -&gt; any()), (map() -&gt; any())) ::
  {:ok, Yog.graph()} | {:error, term()}
```

Reads a graph from a GEXF file with custom data mappers.

Raises `ArgumentError` if path is not a binary string or mappers are invalid.

Time complexity: $\mathcal{O}(V + E)$ + file I/O

# `serialize`

```elixir
@spec serialize(Yog.graph() | Yog.DAG.t()) :: String.t()
```

Serializes a graph to GEXF format using default attribute conversion.

Raises `ArgumentError` if graph is invalid.

Time complexity: $\mathcal{O}(V + E)$

# `serialize_with`

```elixir
@spec serialize_with((any() -&gt; map()), (any() -&gt; map()), Yog.graph() | Yog.DAG.t()) ::
  String.t()
```

Serializes a graph to GEXF format with custom attribute mappers.

Raises `ArgumentError` if mappers or graph are invalid.

Time complexity: $\mathcal{O}(V + E)$

# `serialize_with_options`

```elixir
@spec serialize_with_options(
  (any() -&gt; map()),
  (any() -&gt; map()),
  tuple(),
  Yog.graph() | Yog.DAG.t()
) ::
  String.t()
```

Serializes a graph to GEXF format with custom attribute mappers and options.

Raises `ArgumentError` if arguments or options are invalid.

Time complexity: $\mathcal{O}(V + E)$

# `write`

```elixir
@spec write(String.t(), Yog.graph() | Yog.DAG.t()) :: {:ok, nil} | {:error, atom()}
```

Writes a graph to a GEXF file using default attribute conversion.

Raises `ArgumentError` if path is not a binary string or graph is invalid.

Time complexity: $\mathcal{O}(V + E)$ + file I/O

# `write_with`

```elixir
@spec write_with(
  String.t(),
  (any() -&gt; map()),
  (any() -&gt; map()),
  Yog.graph() | Yog.DAG.t()
) ::
  {:ok, nil} | {:error, atom()}
```

Writes a graph to a GEXF file with custom attribute mappers.

Raises `ArgumentError` if path is not a binary string or graph/mappers are invalid.

Time complexity: $\mathcal{O}(V + E)$ + file I/O

---

*Consult [api-reference.md](api-reference.md) for complete listing*
