GithubHelp home page GithubHelp logo

xmlparser's Introduction

XMLParser

A intuitive XMLParser entirely implemented in LuaU
Parses XML strings into similar AST
Also Parses AST back into XML

Guide

Supports
Install
Usage
API
Maintainers

Supports

  • Prologs
  • Tags
  • Singles
  • Comments

Install

Roblox Console

-- Run in Roblox Studio Console
local HttpService = game:GetService("HttpService"); 
local ReplicatedStorage = game:GetService("ReplicatedStorage");
local LastValue = HttpService.HttpEnabled

HttpService.HttpEnabled = true

local ChalkModule = Instance.new("ModuleScript");
ChalkModule.Name = "XML";
ChalkModule.Parent = ReplicatedStorage;

local Request = HttpService:RequestAsync({
    Url = "https://raw.githubusercontent.com/Perthys/XMLParser/main/source/main.lua";
    Method = "GET";
});

HttpService.HttpEnabled = LastValue

if Request.Success and Request.StatusCode == 200 then
    ChalkModule.Source = Request.Body

    print("Successfully installed XMLParser module. At:", ChalkModule);
else
    error("Failed to install XMLParser module.");
end

Wally

xmlparser = "perthys/[email protected]"

Usage

Example

local ReplicatedStorage = game:GetService("ReplicatedStorage");
local XML = require(ReplicatedStorage:WaitForChild("XML"));

local TagStart = `<b>`;
local TagEnd = `</b>`;

local TagStartArg = `<font size="50">`
local TagEndArg = `</font>`

local Single = `<image ImageID="rbxassetid://15102015050" OtherArgument="test"/>`
local Prolog = `<?xml version="1.0" encoding="UTF-8"?>`
local Comment = `<!-- text -->`

local Text = "hello";

Text = `{TagStart}{Text}{TagEnd}`
Text = `{TagStartArg}{Text}{TagEndArg}`
Text = `{Single}{Text}`
Text = `{Prolog}{Text}`
Text = `{Comment}{Text}`

print(Text)

local Tree = XML:GenerateTreeFromXML(Text); print(Tree)
local NewText = XML:GenerateXMLFromTree(Tree); print(NewText == Text) -- true

Example Output

local ReplicatedStorage = game:GetService("ReplicatedStorage");
local XML = require(ReplicatedStorage:WaitForChild("XML"));

local TagStart = `<b>`;
local TagEnd = `</b>`;

local TagStartArg = `<font size="50">`
local TagEndArg = `</font>`

local Single = `<image ImageID="rbxassetid://15102015050" OtherArgument="test"/>`
local Prolog = `<?xml version="1.0" encoding="UTF-8"?>`
local Comment = `<!-- text -->`

local Text = "hello";

Text = `{TagStart}{Text}{TagEnd}`
Text = `{TagStartArg}{Text}{TagEndArg}`
Text = `{Single}{Text}`
Text = `{Prolog}{Text}`
Text = `{Comment}{Text}`

local Tree = {
    TagType = "ROOT",
    Attributes = {},
    Children = {
        {
            TagType = "COMMENT",
            Attributes = {
                {
                    Value = " text ",
                    Type = "Comment"
                }
            },
            Children = {},
            Type = "COMMENT"
        },
        {
            TagType = "xml",
            Attributes = {
                {
                    Value = `"1.0"`,
                    Type = "version"
                },
                {
                    Value = `"UTF-8"`,
                    Type = "encoding"
                }
            },
            Children = {},
            Type = "PROLOG"
        },
        {
            TagType = "image",
            Attributes = {
                {
                    Value = `"rbxassetid://15102015050"`,
                    Type = "ImageID"
                },
                {
                    Value = `"test"`,
                    Type = "OtherArgument"
                }
            },
            Children = {},
            Type = "SINGLE"
        },
        {
            TagType = "font",
            Attributes = {
                {
                    Value = `"50"`,
                    Type = "size"
                }
            },
            Children = {
                {
                    TagType = "b",
                    Attributes = {},
                    Children = {
                        {
                            TagType = "String",
                            Attributes = {
                                {
                                    Value = "hello",
                                    Type = "String"
                                }
                            },
                            Children = {},
                            Type = "STRING"
                        }
                    },
                    Type = "TAG"
                }
            },
            Type = "TAG"
        }
    },
    Type = "ROOT"
}

print(Text == XML:GenerateXMLFromTree(Tree)) -- true

API

XML:GenerateTreeFromXML(XML: string) -> XML_AST: {}
XML:GenerateXMLFromTree(XML_AST: {}) -> XML: string

Maintainers

xmlparser's People

Contributors

perthys avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.