/java-xml2lua

Java Xml2Lua: command-line tool and library to convert XML to Lua format ☕️📑💱

Primary LanguageJavaGNU General Public License v3.0GPL-3.0

Java Xml2Lua Buy Me A Coffee

Build Status Maven Central Javadocs GPL licensed

The Java Xml2Lua allows parseing a XML file and converting it to Lua file, represented as a table, the native data structure of the Lua language.

It gets a XML file such as the following as input:

<products>
	<product id="12">
	  <description>TV 32''</description>
	  <brand>Samsung</brand>
	  <price>1200</price>
	</product>
	<product id="150">
	  <description>Netbook</description>
	  <brand>Asus</brand>
	  <price>900</price>
	</product>
</products>

Then, it converts it to a Lua file, representing the XML data as a Lua table:

products =  {
  [12]={
    description = "TV 32''", brand = "Samsung", price = "1200", 
  },
  [150]={
    description = "Netbook", brand = "Asus", price = "900", 
  },
  [198]={
    description = "Laser Printer", brand = "Samsung", price = "399", 
  },
}

Using it as a Maven dependency into your own project

The library can be added as a Maven dependency into your own project, by adding the following code to your pom.xml file:

<dependency>
    <groupId>com.manoelcampos</groupId>
    <artifactId>xml2lua</artifactId>
    <version>1.0.0</version>
</dependency>

Using the Xml2Lua class to convert a XML to a Lua file requires just few lines of code:

Xml2Lua parser = new Xml2Lua(xmlFilePath);
parser.convert();
System.out.printf("Lua file generated at %s.\n", parser.getLuaFileName());

Using it as a command line tool

You can use the available command tool to convert XML to Lua using the command line. If you downloaded the project source code, when you build it using mvn clean install or some IDE, a jar file will be created inside the target directory.

Alternatively, you can simply download the jar file from the releases page.

Once you have the jar file, you can run it as below:

java -jar xml2lua.jar XmlFilePath

The tool will generate a Lua file with the same name of the XML file, inside the directory of the XML file.