ProductPromotion
Logo

Elixir

made by https://0x3d.site

GitHub - nhu313/Quinn: XML parser for Elixir
XML parser for Elixir. Contribute to nhu313/Quinn development by creating an account on GitHub.
Visit Site

GitHub - nhu313/Quinn: XML parser for Elixir

GitHub - nhu313/Quinn: XML parser for Elixir

Quinn

A simple XML parser in Elixir aims to parse rss/atom feeds. I'm currently using xmerl_scan.string to parse the xml. I'm a bit busy so I may take awhile to response and/or update. Feel free to send a pull request. Otherwise, check out hex for other XML parsers that may be better maintained.

Parsing

Quinn.parse("<head><title short_name = \"yah\">Yahoo</title><title:content>Bing</title:content></head>")

Calling parse on the xml will produce

[%{attr: [], name: :head,
   value: [%{attr: [short_name: "yah"], name: :title, value: ["Yahoo"]},
           %{attr: [], name: :"title:content", value: ["Bing"]}]}]

Parsing without namespaces(key prefix)

xml = "<m:return xsi:type="d4p1:Answer">
      <d4p1:Title> Title </d4p1:Title>
      <d4p1:Description> Description </d4p1:Description>
     </m:return>"

Quinn.parse(xml, %{strip_namespaces: true})

Calling parse on the xml will produce

[%{attr: ["xsi:type": "d4p1:Answer"],
   name: :return,
   value: [%{attr: [], name: :title, value: ["Title"]},
%{attr: [], name: :description, value: ["Description"]}]}]

Parsing comments

xml = ~s(<head><title short_name = "yah">Yahoo</title><!--- <test pattern="SECAM" /><test pattern="NTSC" /> --></head>)
result = Quinn.parse(xml, %{comments: true})

The xml above will give you this. Note the name is comments.

[%{attr: [],
   name: :head,
   value: [%{attr: [short_name: "yah"], name: :title, value: ["Yahoo"]},
           %{attr: [], name: :comments, value: ~s(- <test pattern="SECAM" /><test pattern="NTSC" />)}]}]

Parsing - Attributes as map

xml = ~s(<m:return xsi:type="d4p1:Answer" desc="bla"><d4p1:Title> Title </d4p1:Title><d4p1:Description> Description </d4p1:Description></m:return>)

result = Quinn.parse(xml, %{map_attributes: true})

The xml above will give you the attributes in map

	    expected = [%{attr: %{"xsi:type": "d4p1:Answer", desc: "bla"},
	                  name: :"m:return",
	                  value: [%{attr: %{}, name: :"d4p1:Title", value: ["Title"]},
	                %{attr: %{},
	                  name: :"d4p1:Description",
	                  value: ["Description"]}]}]

Finding nodes

Suppose you want to find all the body nodes from this structure:

structure = %{attr: [],
              name: :html,
              value: [%{attr: [], name: :head, value: ["title"]},
                      %{attr: [], name: :title, value: []},
                      %{attr: [], name: :body, value: ["body1", "body2"]},
                      %{attr: [], name: :footer, value: [%{attr: [], name: :line, value: ["this"]}]},
                      %{attr: [], name: :body, value: [%{attr: [], name: :line, value: ["that"]}]},
                      %{attr: [], name: :"content:encoded", value: ["<p>comet!!</p>"]}]}

You can call

Quinn.find(structure, :body)

This will be the result:

[%{attr: [], name: :body, value: ["body1", "body2"]},
 %{attr: [], name: :body, value: [%{attr: [], name: :line, value: ["that"]}]}]

Or given the structure above, you want to find the node line inside body, then you can invoke it like this:

Quinn.find(structure, [:body, :line])

The result will be

[%{attr: [], name: :line, value: ["that"]}]

Please refer to the tests if you want to see more example on how it is used.

Please let me know if you come across any problem. I'm still new to Elixir so feel free to contribute or clean up the code.

License

Quinn source code is released under Apache 2 License. Check LICENSE file for more information.

Articles
to learn more about the elixir concepts.

Resources
which are currently available to browse on.

mail [email protected] to add your project or resources here 🔥.

FAQ's
to know more about the topic.

mail [email protected] to add your project or resources here 🔥.

Queries
or most google FAQ's about Elixir.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory