mirror of
https://github.com/odin-lang/Odin.git
synced 2026-06-05 10:14:05 +00:00
[xml] Initial implementation of core:encoding/xml.
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?
This commit is contained in:
55
core/encoding/xml/example/xml_example.odin
Normal file
55
core/encoding/xml/example/xml_example.odin
Normal file
@@ -0,0 +1,55 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user