README.md

# ElixirXML

ElixirXML (based in [Elixml](https://github.com/mlankenau/elixml)) is an improved and optimized XML library for Elixir that makes it easy to:

- Parse XML files (with improved performance)
- Query XML
  - Optimized searching mechanism
  - XPath (in progress)
- Namespace support (implemented)
- Export to file/text (enhanced implementation)
- Compose documents
  - Simple to use with maps
  - DSL support (under development)
  
## Installation

If [available in Hex](https://hex.pm/docs/publish), the package can be installed by adding `elixir_xml` to your list of dependencies in `mix.exs`:

```elixir
def deps do
  [
    {:elixir_xml, github: "https://github.com/OscarTinajero117/elixir_xml"}
  ]
end

```

## Usage

### Parse an XML file

Consider the following example XML file my_file.xml:

```xml
<root>
  <group_a id="1">
    <el1>a_1</el1>
    <el2>a_2</el2>
  </group_a>
  <group_b>
    <el1>b_1</el1>
    <el2>b_2</el2>
  </group_b>
  <group_c>
    <child1>
      <subchild>foo</subchild>
    </child1>
  </group_c>
</root>
```

You can load it with:

```elixir
mydoc =
  File.read!("my_file.xml")
  |> ElixirXML.parse

# returns the root element like
# %{name: "root", children: [...], attributes: [...]}
```

### Find elements

```sh
ElixirXML.find(mydoc, "//group_a")
# returns the list of elements found (only one)
```

### Access text

```sh
ElixirXML.find(mydoc, "//subchild") |> hd |> ElixirXML.text()
# returns "foo"
```

### Access attributes

```sh
ElixirXML.find(mydoc, "//group_a") |> hd |> ElixirXML.attribute("id")
# returns "1"
```

### Reconstruct XML Document

```elixir
child1 = ElixirXML.find(mydoc, "//child1") |> hd
ElixirXML.format_document(child1)
# returns
# """
#  <?xml version="1.0" encoding="UTF-8"?>
#  <child1>
#    <subchild>foo</subchild>
#  </child1>
# """
```

## Features

- Improved parsing speed: Optimized to handle large XML files efficiently.
- Namespace support: Now fully supports XML namespaces.
- XPath support: The XPath querying is under development but planned to be released soon.
- Document composition: Easy to build new XML documents with maps, with plans for a flexible DSL for advanced use cases.

## Documentation

Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc) and published on [HexDocs](https://hexdocs.pm). Once published, the docs can be found at [https://hexdocs.pm/ElixirXML](https://hexdocs.pm/ElixirXML).