Integrate the xml processing with the rest of the project
This commit is contained in:
@@ -457,8 +457,10 @@ STRING FUNCTIONS:
|
||||
format(s, ...) - Formats string using Lua string.format
|
||||
trim(s) - Removes leading/trailing whitespace
|
||||
strsplit(inputstr, sep) - Splits string by separator (default: whitespace)
|
||||
fromCSV(csv, delimiter, hasHeaders) - Parses CSV text into rows of fields (delimiter defaults to ",", hasHeaders defaults to false)
|
||||
toCSV(rows, delimiter) - Converts table of rows to CSV text format (delimiter defaults to ",")
|
||||
fromCSV(csv, options) - Parses CSV text into rows of fields
|
||||
options: {delimiter=",", hasheader=false, hascomments=false}
|
||||
toCSV(rows, options) - Converts table of rows to CSV text format
|
||||
options: {delimiter=",", hasheader=false}
|
||||
num(str) - Converts string to number (returns 0 if invalid)
|
||||
str(num) - Converts number to string
|
||||
is_number(str) - Returns true if string is numeric
|
||||
@@ -467,6 +469,31 @@ TABLE FUNCTIONS:
|
||||
dump(table, depth) - Prints table structure recursively
|
||||
isArray(t) - Returns true if table is a sequential array
|
||||
|
||||
XML HELPER FUNCTIONS:
|
||||
findElements(root, tagName) - Find all elements with specific tag name
|
||||
visitElements(root, callback) - Visit all elements recursively
|
||||
callback(element, depth, path)
|
||||
filterElements(root, predicate) - Find elements matching condition
|
||||
predicate(element) returns true/false
|
||||
getNumAttr(element, attrName) - Get numeric attribute value
|
||||
setNumAttr(element, attrName, value) - Set numeric attribute value
|
||||
modifyNumAttr(element, attrName, func)- Modify numeric attribute with function
|
||||
func(currentValue) returns newValue
|
||||
hasAttr(element, attrName) - Check if attribute exists
|
||||
getAttr(element, attrName) - Get attribute value as string
|
||||
setAttr(element, attrName, value) - Set attribute value
|
||||
getText(element) - Get element text content
|
||||
setText(element, text) - Set element text content
|
||||
|
||||
JSON HELPER FUNCTIONS:
|
||||
visitJSON(data, callback) - Visit all values in JSON structure
|
||||
callback(value, key, parent)
|
||||
findInJSON(data, predicate) - Find values matching condition
|
||||
predicate(value, key, parent) returns true/false
|
||||
modifyJSONNumbers(data, predicate, modifier) - Modify numeric values
|
||||
predicate(value, key, parent) returns true/false
|
||||
modifier(currentValue) returns newValue
|
||||
|
||||
HTTP FUNCTIONS:
|
||||
fetch(url, options) - Makes HTTP request, returns response table
|
||||
options: {method="GET", headers={}, body=""}
|
||||
@@ -480,12 +507,31 @@ UTILITY FUNCTIONS:
|
||||
print(...) - Prints arguments to Go logger
|
||||
|
||||
EXAMPLES:
|
||||
-- Math
|
||||
round(3.14159, 2) -> 3.14
|
||||
min(5, 3) -> 3
|
||||
|
||||
-- String
|
||||
strsplit("a,b,c", ",") -> {"a", "b", "c"}
|
||||
upper("hello") -> "HELLO"
|
||||
min(5, 3) -> 3
|
||||
num("123") -> 123
|
||||
is_number("abc") -> false
|
||||
fetch("https://api.example.com/data")
|
||||
re("(\\w+)@(\\w+)", "user@domain.com") -> {"user@domain.com", "user", "domain.com"}`
|
||||
|
||||
-- XML (where root is XML element with _tag, _attr, _children fields)
|
||||
local items = findElements(root, "Item")
|
||||
for _, item in ipairs(items) do
|
||||
modifyNumAttr(item, "Weight", function(w) return w * 2 end)
|
||||
end
|
||||
|
||||
-- JSON (where data is parsed JSON object)
|
||||
visitJSON(data, function(value, key, parent)
|
||||
if type(value) == "number" and key == "price" then
|
||||
parent[key] = value * 1.5
|
||||
end
|
||||
end)
|
||||
|
||||
-- HTTP
|
||||
local response = fetch("https://api.example.com/data")
|
||||
if response.ok then
|
||||
print(response.body)
|
||||
end`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user