All Projects β†’ manoelcampos β†’ Xml2lua

manoelcampos / Xml2lua

Licence: mit
XML Parser written entirely in Lua that works for Lua 5.1+. Convert XML to and from Lua Tables πŸŒ–πŸ’±

Programming Languages

lua
6591 projects

Projects that are alternatives of or similar to Xml2lua

Fuzi
A fast & lightweight XML & HTML parser in Swift with XPath & CSS support
Stars: ✭ 894 (+496%)
Mutual labels:  xml, parser, xml-parser
Xml Js
Converter utility between XML text and Javascript object / JSON text.
Stars: ✭ 874 (+482.67%)
Mutual labels:  xml, parser, xml-parser
Dasel
Query, update and convert data structures from the command line. Comparable to jq/yq but supports JSON, TOML, YAML, XML and CSV with zero runtime dependencies.
Stars: ✭ 759 (+406%)
Mutual labels:  xml, parser, xml-parser
Parse Xml
A fast, safe, compliant XML parser for Node.js and browsers.
Stars: ✭ 184 (+22.67%)
Mutual labels:  xml, parser, xml-parser
Posthtml
PostHTML is a tool to transform HTML/XML with JS plugins
Stars: ✭ 2,737 (+1724.67%)
Mutual labels:  xml, parser, xml-parser
Sax Wasm
The first streamable, fixed memory XML, HTML, and JSX parser for WebAssembly.
Stars: ✭ 89 (-40.67%)
Mutual labels:  xml, parser, xml-parser
Hquery.php
An extremely fast web scraper that parses megabytes of invalid HTML in a blink of an eye. PHP5.3+, no dependencies.
Stars: ✭ 295 (+96.67%)
Mutual labels:  xml, parser, xml-parser
Oga
Read-only mirror of https://gitlab.com/yorickpeterse/oga
Stars: ✭ 1,147 (+664.67%)
Mutual labels:  xml, parser, xml-parser
Xmlbuilder2
An XML builder for node.js
Stars: ✭ 143 (-4.67%)
Mutual labels:  xml, xml-parser
Xylophone
Xylophone
Stars: ✭ 23 (-84.67%)
Mutual labels:  xml, xml-parser
Cheatyxml
CheatyXML is a Swift framework designed to manage XML easily
Stars: ✭ 23 (-84.67%)
Mutual labels:  xml, xml-parser
Easyxml
Simplifies parsing and modifying of (huge) XML streams (files) based on the StAX parser with combination of JAXB or JDom2
Stars: ✭ 6 (-96%)
Mutual labels:  xml, xml-parser
Fast Xml Parser
Validate XML, Parse XML to JS/JSON and vise versa, or parse XML to Nimn rapidly without C/C++ based libraries and no callback
Stars: ✭ 1,021 (+580.67%)
Mutual labels:  xml, parser
Xslt Processor
A JavaScript XSLT processor without native library dependencies
Stars: ✭ 50 (-66.67%)
Mutual labels:  xml, xml-parser
Omniparser
omniparser: a native Golang ETL streaming parser and transform library for CSV, JSON, XML, EDI, text, etc.
Stars: ✭ 148 (-1.33%)
Mutual labels:  xml, parser
Libexpat
🌿 Expat library: Fast streaming XML parser written in C; in the process of migrating from SourceForge to GitHub
Stars: ✭ 549 (+266%)
Mutual labels:  xml, xml-parser
Corexlsx
Excel spreadsheet (XLSX) format parser written in pure Swift
Stars: ✭ 481 (+220.67%)
Mutual labels:  xml, parser
Android Gpx Parser
A library to parse XML Gpx files, built for Android.
Stars: ✭ 79 (-47.33%)
Mutual labels:  xml, xml-parser
Xmlparser
A low-level, pull-based, zero-allocation XML 1.0 parser.
Stars: ✭ 73 (-51.33%)
Mutual labels:  xml, parser
Woodstox
The gold standard Stax XML API implementation. Now at Github.
Stars: ✭ 145 (-3.33%)
Mutual labels:  xml, xml-parser

:source-highlighter: highlightjs :numbered: :unsafe:

= xml2lua image:https://travis-ci.org/manoelcampos/xml2lua.svg?branch=master[Build Status,link=https://travis-ci.org/manoelcampos/xml2lua] image:http://img.shields.io/badge/license-MIT-brightgreen.svg[MIT license,link=http://opensource.org/licenses/MIT]

pass:[Buy Me A Coffee]

ifdef::env-github[] :outfilesuffix: .adoc :caution-caption: πŸ”₯ :important-caption: ❗️ :note-caption: πŸ“Ž :tip-caption: πŸ’‘ :warning-caption: ⚠️ endif::[]

image:conversion-ways.png[]

xml2lua is an XML parser written entirely in Lua which doesn't depend on any external C/C++ library. It works for Lua 5.1 to 5.3 and enables:

  • parsing an XML string into a Lua Table;
  • converting a Lua Table to an XML string.

This version was adapted to work with Lua 5 and can be used in Lua applications, including interactive Digital Television (DTV) http://gingancl.org.br/en[Ginga NCL applications] for the http://www.dtv.org.br[Brazilian DTV System] (worldwide known as https://en.wikipedia.org/wiki/ISDB-T_International[ISDB-T International or ISDB-Tb]).

The original parser was written by Paul Chakravarti and is available on http://lua-users.org/wiki/LuaXml[LuaUsers].

== Installation

=== From LuaRocks repository

The best way to download the module is using https://luarocks.org/modules/manoelcampos/xml2lua[LuaRocks] at the command line:

[source,bash]

luarocks install xml2lua

=== From local sources

Download the source files using the download button above or type at a terminal:

[source,bash]

git clone https://github.com/manoelcampos/xml2lua.git

Finally, enter the directory where the source files were downloaded and type:

[source,bash]

luarocks make

== How to use

=== Parsing an XML String into a Lua Table

A simplified example which parses an XML directly from a string is presented below. There are some caveats to deal with when an XML has just one tag. Check the link:example1.lua[example1.lua] for details.

[source,lua]

local xml2lua = require("xml2lua") --Uses a handler that converts the XML to a Lua table local handler = require("xmlhandler.tree")

local xml = [[ Manoel Palmas-TO University of BrasΓ­lia BrasΓ­lia-DF

]]

--Instantiates the XML parser local parser = xml2lua.parser(handler) parser:parse(xml)

--Manually prints the table (since the XML structure for this example is previously known) for i, p in pairs(handler.root.people.person) do print(i, "Name:", p.name, "City:", p.city, "Type:", p._attr.type) end

=== Converting a Lua Table to an XML String

[source,lua]

local xml2lua = require("xml2lua") local people = { person = { {name="Manoel", city="Palmas-TO", _attr={ type='natural' } }, {name="Breno", city="Palmas-TO", _attr={ type='legal' } } } }

print("People Table\n") xml2lua.printable(people)

print() print("XML Representation\n") print(xml2lua.toXml(people, "people"))

== Command line tool

You can use a command line tool to try parsing XML files. Execute lua testxml.lua -help on the terminal for more details.

== Running tests

=== Requeriments

You must have https://docs.docker.com/compose/install/[installed docker and docker compose].

=== How to

[source,bash]

make lint # to run the lint check make test # to run the acceptance tests

== License

This code is freely distributable under the terms of the link:LICENSE[MIT license].

== Authors

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].