https://github.com/rzcastilho/xmlx
Elixir native XML parser that enables search by attribute or element names
https://github.com/rzcastilho/xmlx
elixir parser xml
Last synced: 26 days ago
JSON representation
Elixir native XML parser that enables search by attribute or element names
- Host: GitHub
- URL: https://github.com/rzcastilho/xmlx
- Owner: rzcastilho
- License: wtfpl
- Created: 2016-10-24T15:26:48.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2021-10-14T19:20:27.000Z (over 4 years ago)
- Last Synced: 2025-12-13T02:12:23.205Z (6 months ago)
- Topics: elixir, parser, xml
- Language: Elixir
- Homepage:
- Size: 42 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Xmlx
[](https://github.com/rzcastilho/xmlx/actions/workflows/ci.yml/badge.svg)
[](https://coveralls.io/github/rzcastilho/xmlx)
[](https://hex.pm/packages/xmlx)
[](https://hex.pm/packages/xmlx)
[](https://github.com/rzcastilho/xmlx/blob/master/LICENSE)
Elixir native XML parser that enables search using attribute or element names
## Installation
The package can be installed by adding `xmlx` to your list of dependencies in `mix.exs`:
```elixir
def deps do
[{:xmlx, "~> 0.1.1"}]
end
```
## Usage
### XML Example (simple.xml)
```xml
Tove
Jani
Reminder
Don't forget me this weekend!
```
1. Document parse
```elixir
File.read!("simple.xml")
|> Xmlx.parse()
```
```elixir
[
note: [
to: [text: "Tove"],
from: [text: "Jani"],
heading: [text: "Reminder"],
body: ["@type": "text", text: "Don't forget me this weekend!"]
]
]
```
2. Find by element name
```elixir
File.read!("simple.xml")
|> Xmlx.parse()
|> Xmlx.find(:from)
```
or
```elixir
File.read!("simple.xml")
|> Xmlx.parse()
|> Xmlx.find("from")
```
result
```elixir
[from: [text: "Jani"]]
```
3. Find by attribute name
```elixir
File.read!("simple.xml")
|> Xmlx.parse()
|> Xmlx.find(:"@type")
```
or
```elixir
File.read!("simple.xml")
|> Xmlx.parse()
|> Xmlx.find("@type")
```
result
```elixir
["@type": "text"]
```
### WSDL Example (simple.wsdl)
```xml
snowboarding-info.com Endorsement Service
```
1. Document parse
```elixir
File.read!("simple.wsdl")
|> Xmlx.parse()
```
```elixir
[
"{http://schemas.xmlsoap.org/wsdl/}definitions": [
"@name": "EndorsementSearch",
"@targetNamespace": "http://namespaces.snowboard-info.com",
"{http://schemas.xmlsoap.org/wsdl/}message": [
"@name": "GetEndorsingBoarderRequest",
"{http://schemas.xmlsoap.org/wsdl/}part": [
"@name": "body",
"@element": "esxsd:GetEndorsingBoarder"
]
],
"{http://schemas.xmlsoap.org/wsdl/}message": [
"@name": "GetEndorsingBoarderResponse",
"{http://schemas.xmlsoap.org/wsdl/}part": [
"@name": "body",
"@element": "esxsd:GetEndorsingBoarderResponse"
]
],
"{http://schemas.xmlsoap.org/wsdl/}portType": [
"@name": "GetEndorsingBoarderPortType",
"{http://schemas.xmlsoap.org/wsdl/}operation": [
"@name": "GetEndorsingBoarder",
"{http://schemas.xmlsoap.org/wsdl/}input": [
"@message": "es:GetEndorsingBoarderRequest"
],
"{http://schemas.xmlsoap.org/wsdl/}output": [
"@message": "es:GetEndorsingBoarderResponse"
],
"{http://schemas.xmlsoap.org/wsdl/}fault": [
"@message": "es:GetEndorsingBoarderFault"
]
]
],
"{http://schemas.xmlsoap.org/wsdl/}binding": [
"@name": "EndorsementSearchSoapBinding",
"@type": "es:GetEndorsingBoarderPortType",
"{http://schemas.xmlsoap.org/wsdl/soap/}binding": [
"@style": "document",
"@transport": "http://schemas.xmlsoap.org/soap/http"
],
"{http://schemas.xmlsoap.org/wsdl/}operation": [
"@name": "GetEndorsingBoarder",
"{http://schemas.xmlsoap.org/wsdl/soap/}operation": [
"@soapAction": "http://www.snowboard-info.com/EndorsementSearch"
],
"{http://schemas.xmlsoap.org/wsdl/}input": [
"{http://schemas.xmlsoap.org/wsdl/soap/}body": [
"@use": "literal",
"@namespace": "http://schemas.snowboard-info.com/EndorsementSearch.xsd"
]
],
"{http://schemas.xmlsoap.org/wsdl/}output": [
"{http://schemas.xmlsoap.org/wsdl/soap/}body": [
"@use": "literal",
"@namespace": "http://schemas.snowboard-info.com/EndorsementSearch.xsd"
]
],
"{http://schemas.xmlsoap.org/wsdl/}fault": [
"{http://schemas.xmlsoap.org/wsdl/soap/}body": [
"@use": "literal",
"@namespace": "http://schemas.snowboard-info.com/EndorsementSearch.xsd"
]
]
]
],
"{http://schemas.xmlsoap.org/wsdl/}service": [
"@name": "EndorsementSearchService",
"{http://schemas.xmlsoap.org/wsdl/}documentation": [
text: "snowboarding-info.com Endorsement Service"
],
"{http://schemas.xmlsoap.org/wsdl/}port": [
"@name": "GetEndorsingBoarderPort",
"@binding": "es:EndorsementSearchSoapBinding",
"{http://schemas.xmlsoap.org/wsdl/soap/}address": [
"@location": "http://www.snowboard-info.com/EndorsementSearch"
]
]
]
]
]
```
2. Find by element name
```elixir
File.read!("simple.wsdl")
|> Xmlx.parse()
|> Xmlx.find(:"{http://schemas.xmlsoap.org/wsdl/}port")
```
or
```elixir
File.read!("simple.wsdl")
|> Xmlx.parse()
|> Xmlx.find("{http://schemas.xmlsoap.org/wsdl/}port")
```
or
```elixir
File.read!("simple.wsdl")
|> Xmlx.parse()
|> Xmlx.find("port")
```
result
```elixir
[
"{http://schemas.xmlsoap.org/wsdl/}port": [
"@name": "GetEndorsingBoarderPort",
"@binding": "es:EndorsementSearchSoapBinding",
"{http://schemas.xmlsoap.org/wsdl/soap/}address": [
"@location": "http://www.snowboard-info.com/EndorsementSearch"
]
]
]
```
3. Find by attribute name
```elixir
File.read!("simple.wsdl")
|> Xmlx.parse()
|> Xmlx.find(:"@location")
```
or
```elixir
File.read!("simple.wsdl")
|> Xmlx.parse()
|> Xmlx.find("@location")
```
result
```elixir
["@location": "http://www.snowboard-info.com/EndorsementSearch"]
```