This is an XML parser and DOM handling library for Jai.
Parses most XML correctly. Fails on certain rare <!DOCTYPE>
declarations. Doesn't handle encodings other than UTF-8 and ASCII, except by accident.
Benchmarked on a test suite based on the XML conformance tests, with 3111 tests, of which 90% pass.
Average speed is 113µs per test.
Runtime: 351301 µs.
Passed: 2818 (90.5818%)
Failed: 293 (9.4182%)
Total : 3111
To run the tests/benchmarks, compile test.jai
and run. We don't distribute most of the test data files, so use test_data/fetch.sh
to fetch them.
See examples in the examples/
directory.
While you can traverse the XML hierarchy manually, there are both callback-based walkers
and a for_expansion
defined. The for expansion allows you to run for
on a node and it will walk its children, breadth first.
Note: The depth-first callback walker will visit children in the reverse order of their parents. This may seem confusing, and should probably be changed, but it's the easiest way to implement this.
xml_parse :: (buffer: string) -> *XMLNode, XMLParseResult
xml_parse_file :: (file: string) -> *XMLNode, XMLParseResult
node_allocate :: inline () -> *XMLNode
node_create :: (type: XMLNodeType) -> *XMLNode
node_free :: (node: *XMLNode)
node_append :: (child: *XMLNode, node: *XMLNode)
node_append_new :: (node: *XMLNode, type: XMLNodeType) -> *XMLNode
node_prepend :: (child: *XMLNode, node: *XMLNode)
node_insert_after :: (sibling: *XMLNode, node: *XMLNode)
node_insert_before :: (sibling: *XMLNode, node: *XMLNode)
node_remove :: (node: *XMLNode)
node_find_child_by_tag :: (node: *XMLNode, tag: string) -> *XMLNode
node_get_cdata :: (node: *XMLNode) -> string, bool
attribute_allocate :: inline () -> *XMLAttribute
attribute_free :: (attrib: *XMLAttribute)
attribute_get :: (node: *XMLNode, name: string) -> *XMLAttribute
attribute_get_value :: (node: *XMLNode, name: string, default := "") -> string, bool
attribute_append :: (attr: *XMLAttribute, node: *XMLNode)
attribute_append :: (node: *XMLNode, key: string, value: string)
attribute_prepend :: (attr: *XMLAttribute, node: *XMLNode)
attribute_insert_after :: (attr: *XMLAttribute, node: *XMLNode)
attribute_insert_before :: (attr: *XMLAttribute, node: *XMLNode)
attribute_remove :: (attr: *XMLAttribute, node: *XMLNode)
attribute_append_new :: (node: *XMLNode) -> *XMLAttribute
xml_walk_depthfirst :: (node: *XMLNode, callback: XMLNodeWalkCallback)
xml_walk_breadthfirst :: (node: *XMLNode, callback: XMLNodeWalkCallback)
for_expansion :: (node: *XMLNode, body: Code, flags: For_Flags)
- Verify that free-methods are working right
- Add support for ISO-8859
- Add support for UTF-16
- Improve speed of UTF-8 to UTF-32 conversion
- Improve speed of Unicode character class matching
- Add XPath support
- Smári McCarthy
Copyright 2014 Smári McCarthy
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.