All Projects → joshnuss → Xml_builder

joshnuss / Xml_builder

Licence: mit
Elixir library for generating XML

Programming Languages

elixir
2628 projects

Labels

Projects that are alternatives of or similar to Xml builder

Binding.scala
Reactive data-binding for Scala
Stars: ✭ 1,539 (+1057.14%)
Mutual labels:  xml
Jstoxml
JavaScript object to XML converter (useful for RSS, podcasts, GPX, AMP, etc)
Stars: ✭ 127 (-4.51%)
Mutual labels:  xml
Feedbundle
A Symfony bundle to build RSS feeds from your entities
Stars: ✭ 130 (-2.26%)
Mutual labels:  xml
Markup.ml
Error-recovering streaming HTML5 and XML parsers
Stars: ✭ 122 (-8.27%)
Mutual labels:  xml
Sepa king
Ruby gem for creating SEPA XML files
Stars: ✭ 125 (-6.02%)
Mutual labels:  xml
Scobot
SCORM API for Content. JavaScript library, QUnit tests and examples.
Stars: ✭ 128 (-3.76%)
Mutual labels:  xml
Lemminx
XML Language Server
Stars: ✭ 117 (-12.03%)
Mutual labels:  xml
Coregpx
A library for parsing and creation of GPX location files. Purely Swift.
Stars: ✭ 132 (-0.75%)
Mutual labels:  xml
Attentionxml
Implementation for "AttentionXML: Label Tree-based Attention-Aware Deep Model for High-Performance Extreme Multi-Label Text Classification"
Stars: ✭ 126 (-5.26%)
Mutual labels:  xml
Svgo
Go Language Library for SVG generation
Stars: ✭ 1,779 (+1237.59%)
Mutual labels:  xml
Snodge
Randomly mutate JSON, XML, HTML forms, text and binary data for fuzz testing
Stars: ✭ 121 (-9.02%)
Mutual labels:  xml
Prettydiff
Beautifier and language aware code comparison tool for many languages. It also minifies and a few other things.
Stars: ✭ 1,635 (+1129.32%)
Mutual labels:  xml
Music Encoding
美 The Music Encoding Initiative schema and guidelines development repository
Stars: ✭ 129 (-3.01%)
Mutual labels:  xml
Saxerator
A SAX-based XML parser for parsing large files into manageable chunks
Stars: ✭ 119 (-10.53%)
Mutual labels:  xml
Servicemix
Apache ServiceMix
Stars: ✭ 131 (-1.5%)
Mutual labels:  xml
Flexlib
FlexLib是一个基于flexbox模型,使用xml文件进行界面布局的框架,融合了web快速布局的能力,让iOS界面开发像写网页一样简单快速
Stars: ✭ 1,569 (+1079.7%)
Mutual labels:  xml
Sitemap
PHP XML Sitemap Generation
Stars: ✭ 128 (-3.76%)
Mutual labels:  xml
Vscode Auto Close Tag
Auto Close Tag for Visual Studio Code
Stars: ✭ 132 (-0.75%)
Mutual labels:  xml
Oq
A performant, and portable jq wrapper to facilitate the consumption and output of formats other than JSON; using jq filters to transform the data.
Stars: ✭ 132 (-0.75%)
Mutual labels:  xml
Myutils
🙏 提供时间轴转星座|生肖工具、系统存储空间获取工具、文件大小格式化工具、获取指定文件大小工具、AES加密解码工具(支持android端平台加密解密,java端和android端相互加密解密)、SharePreference操作工具、 File文件操作工具、日期获取和计算工具、界面跳转Intent操作工具、字符串验证和数值转换操作工具、手机震动工具、系统资源操作工具、网络检测工具、 wifi操作工具、单位换算工具、zip压缩和解压操作工具、XML解析操作工具(只支持几种指定格式)、图片加载和处理工具,数据库操作(增删改查)工具、Base64编码解码工具、MD5加密工具。
Stars: ✭ 130 (-2.26%)
Mutual labels:  xml

XML Builder

CI Module Version Hex Docs Total Download License Last Updated

Overview

An Elixir library for building XML. It is inspired by the late Jim Weirich's awesome builder library for Ruby.

Each XML node is structured as a tuple of name, attributes map, and content/list.

{name, attrs, content | list}

Installation

Add dependency to your project's mix.exs:

def deps do
  [{:xml_builder, "~> 2.1"}]
end

Examples

A simple element

Like <person id="12345">Josh</person>, would look like:

{:person, %{id: 12345}, "Josh"} |> XmlBuilder.generate

An element with child elements

Like <person id="12345"><first>Josh</first><last>Nussbaum</last></person>.

{:person, %{id: 12345}, [{:first, nil, "Josh"}, {:last, nil, "Nussbaum"}]} |> XmlBuilder.generate

Convenience Functions

For more readability, you can use XmlBuilder's methods instead of creating tuples manually.

XmlBuilder.document(:person, "Josh") |> XmlBuilder.generate

Outputs:

<?xml version="1.0" encoding="UTF-8" ?>
<person>Josh</person>

Building up an element

An element can be built using multiple calls to the element function.

import XmlBuilder

def person(id, first, last) do
  element(:person, %{id: id}, [
    element(:first, first),
    element(:last, last)
  ])
end

iex> [person(123, "Steve", "Jobs"),
      person(456, "Steve", "Wozniak")] |> generate

Outputs.

<person id="123">
  <first>Steve</first>
  <last>Jobs</last>
</person>
<person id="456">
  <first>Steve</first>
  <last>Wozniak</last>
</person>

Using keyed lists

The previous example can be simplified using a keyed list.

import XmlBuilder

def person(id, first, last) do
  element(:person, %{id: id}, first: first,
                              last: last)
end

iex> person(123, "Josh", "Nussbaum") |> generate(format: :none)
"<person id=\"123\"><first>Josh</first><last>Nussbaum</last></person>"

Namespaces

To use a namespace, add an xmlns attribute to the root element.

To use multiple schemas, specify a xmlns:nsName attribute for each schema and use a colon : in the element name, ie nsName:elementName.

import XmlBuilder

iex> generate({:example, [xmlns: "http://schemas.example.tld/1999"], "content"})
"<example xmlns=\"http://schemas.example.tld/1999\">content</example>"

iex> generate({:"nsName:elementName", ["xmlns:nsName": "http://schemas.example.tld/1999"], "content"})
"<nsName:elementName xmlns:nsName=\"http://schemas.example.tld/1999\">content</nsName:elementName>"

DOCTYPE declarations

A DOCTYPE can be declared by applying the doctype function at the first position of a list of elements in a document definition:

import XmlBuilder

document([
  doctype("html", public: ["-//W3C//DTD XHTML 1.0 Transitional//EN",
                "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"]),
  element(:html, "Hello, world!")
]) |> generate

Outputs.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>Hello, world!</html>

Encoding

While the output is always UTF-8 and has to be converted in another place, you can override the encoding statement in the XML declaration with the encoding option.

import XmlBuilder

document(:oldschool)
|> generate(encoding: "ISO-8859-1")
|> :unicode.characters_to_binary(:unicode, :latin1)

Outputs.

<?xml version="1.0" encoding="ISO-8859-1"?>
<oldschool/>

Standalone

Should you need standalone="yes" in the XML declaration, you can pass standalone: true as option to the generate/2 call.

import XmlBuilder

document(:outsider)
|> generate(standalone: true)

Outputs.

<?xml version="1.0" standalone="yes"?>
<outsider/>

Formatting

To remove indentation, pass format: :none option to XmlBuilder.generate/2.

doc |> XmlBuilder.generate(format: :none)

The default is to formatting with indentation, which is equivalent to XmlBuilder.generate(doc, format: :indent).

License

This source code is licensed under the MIT License. Copyright (c) 2014-present, Joshua Nussbaum. All rights reserved.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].