danj
New! Parse (and generate) XML with a DSL that is built on top of Ecto.Schema. Makes handling XML easy if you want structs out of XML input.
An example:
defmodule Simple do
use XmlSchema, xml_name: "a"
xml do
xml_tag :x, :string
xml_tag :y, :boolean
xml_one :z, Z do
xml_tag :a, :string
xml_tag :b, :string
end
xml_many :j, J do
xml_tag :q, :string
end
xml_tag :g, {:array, :string}
end
end
This example is illustrated in the module doc
Trending in Announcing
Flop is an Elixir library that applies filtering, ordering and pagination parameters to your Ecto queries.
offset-based pagination with...
New
I needed to reuse React components from my Chrome extension in my Phoenix/LiveView backend. I noticed that for Svelte/Vue, there are live...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Hi all!
I want to present a small library which provides a mix task for generating an Entity-Relationship Diagram for Ecto schemas.
You...
New
Hello
Published a new library - ProcessHub!
ProcessHub is a library designed to manage process distribution within the Elixir cluster. ...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself.
My main conc...
New
This showed up on my feed.. anyone heard of it? Just hype?
Ox Alpha is a reasoning model designed for coding, sustained ag...
New
It’s not that it’s vocabulary is too advanced. It’s something worse.
I get lost trying to follow even a paragraph written by Claude. It’...
New
Today we’re releasing Oban for Python. Not an Oban client in Python. Not a pythonx wrapper embedded in Elixir. Nope, it’s a fully operati...
New
@hugobarauna, Dr. Dimitrios Koutmos (my brother) and I (Alex Koutmos) have been hard at work on writing a book on how you can use Elixir ...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #ai
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 9- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
Eiji
To have some context let’s use you example
XMLfrom documentation:Example file
First of all your code is inspired by
ecto, but have a different naming and way too many logic is in one file.Updated example schema definition
While I understand that using the existing
ectoschema in some cases may be even impossible, I still recommend to support such schema, so in some cases developers could use an existing schemas and define their own ones only when needed.Unfortunately
_attributestag name is correct, so even if it’s an edge case we still support it. Therefore it’s much easier to deal withattrsandcontentsfully separately i.e. we should use a map with such 2 keys.Aggregate is really helpful, but not always desired. Regardless of what’s your defaults (if any) I would recommend to add an option to disable or enable it. This however prevents us from generating maps. Since we have a
Keywordlists it’s really not a big deal and also it allows us to preserve the order which is really important in few cases especially when we want to re-encode saidxmldocument.Same goes for working with whitespace characters. I even gave a real world example for
flokilibrary in the Floki removes blank text nodes without option to avoid this #75 issue.Here are some examples I have prepared:
YourLibName.decode!(xml, aggregate_adjacent_siblings: false, skip_empty_text_nodes: false)
YourLibName.decode!(xml, aggregate_adjacent_siblings: false, skip_empty_text_nodes: true)
YourLibName.decode!(xml, aggregate_adjacent_siblings: true, skip_empty_text_nodes: false)
YourLibName.decode!(xml, aggregate_adjacent_siblings: true, skip_empty_text_nodes: true)
Those are simplest examples, but there are other things to cover:
What to do when said
xmldocument have tags we don’t declare inschema(because for example we don’t need a data from them). You can addstrict_document_structureboolean option, so in let’s say updated documents for some standard (like newerXMLAPI).How to properly deal with attributes. What if we expect some url which is supposed to be in some attribute? Should
strict_document_structurebe also used for attributes? You definitely need someattrDSL.There is no information about comments. Since we can encode
xmlback we most probably want to have said document properly updated without anything missing.Finally some ideas/questions about your code:
The links in documentation does not works.
ex_docfallbacks to default branch which ismain. They should point to a specific version (like within a git’s `tag).I have no idea about
Erlang’s XML parsers. It’s obvious why you didn’t wrote your own, but why did you choose erlsom over Erlang’sxmerl?https://github.com/danj3/xml_schema/blob/fa9d3669d1a1247e20a1c936f3b89cf32637006f/lib/xml_schema.ex#L367-L370
The above code can be written much simpler:
module |> Module.split() |> List.last()Every public function should be documented. Many developers may give up at this point, some may try to check links, but oh, we’re back in 1st point
mix formatis your friend. If you are still lonelycredois another one. Even if you want to do everything yourself then he have even it’s own style guidesupportdirectory name is not bad, but more common for your case isfixtures. The first one is general and when developer see it then first thing coming to mind isphoenix stuff.fixturesis more explicit naming.File.readcalls are not best if you can do that in compile-time.fixturesandxmlin same directory or even in same file. It’s even better than extraFile.read!/1call:XMLdocument parsing. Therefore 99% of your tests looks like:floki,jason,ectoandelixirdocumentations.danj
Released to hex, Version 1.3, improved docs, some attribute handling fixes, better generation support for custom types and arrays, more tests and generation of document examples from tests.
danj
Update to 1.3.0 with improved docs and some refactoring. Xml can be easy! But, it isn’t, this only makes it easier.
danj
xml_schema 2.0.2 released! Use xml as bi-directional structs (extending ecto schema).
In this update:
xml schema 2.0.2 on hex
FeeJai
I just tried that and had a couple of issue with the xml namespaces. Is there a way to add this?
danj
Namespaces are supported, although not documented. For any tag with a namespace, an attribute of
_nswill be set with the namespace. If this doesn’t work for you please detail your situation.FeeJai
I have found the _ns attribute, but this fails on saving to xml. My case is even more complex, though.
I am working on xml files used by tax authorities. They come with xsd files for validation. A good example is this format defined by the OECD (user guide and xsds in the link): https://web-archive.oecd.org/temp/2021-03-24/392446-country-by-country-reporting-xml-schema-user-guide-for-tax-administrations.htm
The file I am trying to generate should then look like this one: oecd_cbcr_example.xml · GitHub
This requires two different namespace prefixes in the tags, to stay compliant with the standard (“cbc” and “cbcstf” in my example). Any way to do that?
danj
The generation side doesn’t use the _ns attributes to add namespaces on output at this point. The information present in the attribute isn’t used at this point. I have some thoughts about how to produce the namespaced xml you’re looking for, but not currently the time to put toward it.
Created issue namespace output currently unsupported · Issue #1 · danj3/xml_schema · GitHub
FeeJai
Thank you. I might find some time to read through your code this weekend.