Skip to content

Latest commit

 

History

History
39 lines (32 loc) · 1.04 KB

README.md

File metadata and controls

39 lines (32 loc) · 1.04 KB

xml.lua

simple xml parser for lua. based on one abandoned project, that was based on some other abandoned project.

installation

  1. Copy the xmlSimple.lua file to your project.
  2. Create a local variable local xml = require("xmlSimple.lua").newParser()
  3. Read xml using xml:ParseXmlText(xmlString) or xml:loadFile(xmlFilename, base)

Parsing XML

<test one="two">
    <three four="five" four="six"/>
    <three>eight</three>
    <nine ten="eleven">twelve</nine>
</test>

You can access values in two ways.

Using the simple method:

xml.test["@one"] == "two"
xml.test.nine["@ten"] == "eleven"
xml.test.nine:value() == "twelve"
xml.test.three[1]["@four"][1] == "five"
xml.test.three[1]["@four"][2] == "six"
xml.test.three[2]:value() == "eight"

or if your XML is a little bit more complicated you can do it like this:

xml:children()[1]:name() == "test"
xml:children()[1]:children()[2]:value() == "eight"
xml:properties()[1] == {name = "one", value = "two"}