https://github.com/manoelcampos/java-xml2lua
Java Xml2Lua: command-line tool and library to convert XML to Lua format ☕️📑💱
https://github.com/manoelcampos/java-xml2lua
converter java lua xml xml2lua
Last synced: 9 months ago
JSON representation
Java Xml2Lua: command-line tool and library to convert XML to Lua format ☕️📑💱
- Host: GitHub
- URL: https://github.com/manoelcampos/java-xml2lua
- Owner: manoelcampos
- License: gpl-3.0
- Created: 2011-08-03T21:46:30.000Z (over 14 years ago)
- Default Branch: master
- Last Pushed: 2021-06-20T00:19:51.000Z (over 4 years ago)
- Last Synced: 2025-02-14T18:20:29.941Z (11 months ago)
- Topics: converter, java, lua, xml, xml2lua
- Language: Java
- Homepage: https://manoelcampos.com/JavaXml2Lua/
- Size: 84 KB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Java Xml2Lua
[](https://github.com/manoelcampos/java-xml2lua/actions/workflows/maven.yml) [](https://maven-badges.herokuapp.com/maven-central/com.manoelcampos/xml2lua) [](https://www.javadoc.io/doc/com.manoelcampos/xml2lua) [](http://www.gnu.org/licenses/gpl-3.0)
The Java Xml2Lua allows parseing a XML file and converting it to [Lua](http://lua.org) file, represented as a [table](https://www.lua.org/pil/2.5.html), the native data structure of the Lua language.
It gets a XML file such as the following as input:
```xml
TV 32''
Samsung
1200
Netbook
Asus
900
```
Then, it converts it to a Lua file, representing the XML data as a Lua table:
```lua
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:
```xml
com.manoelcampos
xml2lua
1.0.0
```
Using the `Xml2Lua` class to convert a XML to a Lua file requires just few lines of code:
```java
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](https://github.com/manoelcampos/JavaXml2Lua/releases) page.
Once you have the jar file, you can run it as below:
```bash
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.