added XML parser

This commit is contained in:
Louis Heredero 2024-05-19 17:29:16 +02:00
parent 44fd298edb
commit 8d93e6473e
Signed by: HEL
GPG Key ID: 8D83DE470F8544E7
2 changed files with 25 additions and 3 deletions

View File

@ -23,7 +23,25 @@
} }
} }
#let load(path-or-schema, config: auto) = { #let parse-raw(schema) = {
let lang = schema.lang
let content = schema.text
if not lang in valid-extensions {
let fmts = valid-extensions.map(fmt => "." + fmt).join(", ")
fmts = "(" + fmts + ")"
panic("Unsupported format '" + lang + "'. Valid formats: " + fmts)
}
if lang == "yaml" {
return yaml.decode(content)
} else if lang == "json" {
return json.decode(content)
} else if lang == "xml" {
return xml-loader.parse(xml.decode(content).first())
}
}
#let load(path-or-schema) = {
let schema = if type(path-or-schema) == str { let schema = if type(path-or-schema) == str {
parse-file(path-or-schema) parse-file(path-or-schema)
} else { } else {

View File

@ -81,8 +81,7 @@
) )
} }
#let load(path) = { #let parse(content) = {
let content = xml(path).first()
let struct-elmts = content.children.filter(e => "tag" in e and e.tag == "structure") let struct-elmts = content.children.filter(e => "tag" in e and e.tag == "structure")
let structures = (:) let structures = (:)
@ -98,3 +97,8 @@
structures: structures structures: structures
) )
} }
#let load(path) = {
let content = xml(path).first()
return parse(content)
}