mirror of
https://github.com/Ed94/Odin.git
synced 2026-06-13 09:22:22 -07:00
b5c828fe4e
A from-scratch XML implementation, loosely modeled on the [spec](https://www.w3.org/TR/2006/REC-xml11-20060816). Features: - Supports enough of the XML 1.0/1.1 spec to handle the 99.9% of XML documents in common current usage. - Simple to understand and use. Small. Caveats: - We do NOT support HTML in this package, as that may or may not be valid XML. If it works, great. If it doesn't, that's not considered a bug. - We do NOT support UTF-16. If you have a UTF-16 XML file, please convert it to UTF-8 first. Also, our condolences. - <[!ELEMENT and <[!ATTLIST are not supported, and will be either ignored or return an error depending on the parser options. TODO: - Optional CDATA unboxing. - Optional `>`, ` `, ` ` and other escape substitution in tag bodies. - Test suite MAYBE: - XML writer? - Serialize/deserialize Odin types?
55 lines
1.0 KiB
Odin
55 lines
1.0 KiB
Odin
package xml_example
|
|
|
|
import "core:encoding/xml"
|
|
import "core:mem"
|
|
import "core:fmt"
|
|
|
|
Error_Handler :: proc(pos: xml.Pos, fmt: string, args: ..any) {
|
|
|
|
}
|
|
|
|
FILENAME :: "../../../../tests/core/assets/xml/nl_NL-xliff-1.0.xliff"
|
|
DOC :: #load(FILENAME)
|
|
|
|
OPTIONS :: xml.Options{
|
|
flags = {
|
|
.Ignore_Unsupported, .Intern_Comments,
|
|
},
|
|
expected_doctype = "",
|
|
}
|
|
|
|
_main :: proc() {
|
|
using fmt
|
|
|
|
println("--- DOCUMENT TO PARSE ---")
|
|
println(string(DOC))
|
|
println("--- /DOCUMENT TO PARSE ---\n")
|
|
|
|
doc, err := xml.parse(DOC, OPTIONS, FILENAME, Error_Handler)
|
|
defer xml.destroy(doc)
|
|
|
|
xml.print(doc)
|
|
|
|
if err != .None {
|
|
printf("Parse error: %v\n", err)
|
|
} else {
|
|
println("DONE!")
|
|
}
|
|
}
|
|
|
|
main :: proc() {
|
|
using fmt
|
|
|
|
track: mem.Tracking_Allocator
|
|
mem.tracking_allocator_init(&track, context.allocator)
|
|
context.allocator = mem.tracking_allocator(&track)
|
|
|
|
_main()
|
|
|
|
if len(track.allocation_map) > 0 {
|
|
println()
|
|
for _, v in track.allocation_map {
|
|
printf("%v Leaked %v bytes.\n", v.location, v.size)
|
|
}
|
|
}
|
|
} |