xml
| Kind | ffi-c |
|---|---|
| Categories | parser ffi data-format |
| Keywords | xml xpath parser libxml2 ffi |
XML parsing, generation, and XPath queries using libxml2
Files
| File | Description |
|---|---|
kit.toml | Package manifest with metadata and dependencies |
src/xml.kit | XML parsing, XPath queries, and document creation |
tests/xml.test.kit | Tests for constants, types, and node variants |
examples/basic.kit | Parse XML and query with XPath expressions |
examples/create.kit | Build XML documents with attributes |
examples/xml.kit | Full demo of parsing, XPath, and RSS feeds |
examples/xpath-advanced.kit | Complex XPath queries and filtering |
LICENSE | MIT license file |
Dependencies
No Kit package dependencies.
Installation
kit add gitlab.com/kit-lang/packages/kit-xml.gitUsage
import Kit.XmlLicense
MIT License - see LICENSE for details.
Exported Functions & Types
XMLError
XML error type for typed error handling.
Variants
XMLParseError {message}XMLXPathError {message}XMLCreateError {message}xml-parse-default
Default XML parsing options.
xml-parse-recover
Recover from parsing errors.
xml-parse-noent
Substitute entity references.
xml-parse-dtdload
Load external DTD.
xml-parse-dtdattr
Default DTD attributes.
xml-parse-dtdvalid
Validate with DTD.
xml-parse-noerror
Suppress error reports.
xml-parse-nowarning
Suppress warning reports.
xml-parse-noblanks
Remove blank nodes.
xml-element-node
XML element node type.
xml-attribute-node
XML attribute node type.
xml-text-node
XML text node type.
xml-cdata-node
XML CDATA section node type.
xml-comment-node
XML comment node type.
xml-document-node
XML document node type.
Node
Represents different types of XML nodes.
Variants
ElementNode {Element}TextNode {String}CommentNode {String}parse
Parses an XML string into a document.
String -> Result XmlDoc XMLError
parse-with-options
Parses an XML string with custom parsing options.
String -> Int -> Result XmlDoc XMLError
parse-file
Parses an XML file into a document.
String -> Result XmlDoc XMLError
free
Frees a document from memory.
XmlDoc -> Void
xpath
Executes an XPath query and returns matching nodes.
XmlDoc -> String -> Result XPathResult XMLError
xpath-ns
Executes an XPath query with namespace prefixes.
XmlDoc -> String -> List (String, String) -> Result XPathResult XMLError
xpath-text
Gets text content from XPath result nodes.
XmlDoc -> String -> Result (List String) XMLError
xpath-first
Gets the first text result from an XPath query.
XmlDoc -> String -> Result String XMLError
xpath-exists?
Checks if an XPath query matches any nodes.
XmlDoc -> String -> Bool
xpath-count
Counts the number of nodes matching an XPath query.
XmlDoc -> String -> Int
root
Gets the root element of a document.
XmlDoc -> Result XmlNode XMLError
name
Gets the name of a node.
XmlNode -> String
text
Gets the text content of a node.
XmlNode -> String
attr
Gets the value of a node attribute.
XmlNode -> String -> Option String
has-attr?
Checks if a node has a specific attribute.
XmlNode -> String -> Bool
node-type
Gets the type of a node.
XmlNode -> Int
is-element?
Checks if a node is an element node.
XmlNode -> Bool
is-text?
Checks if a node is a text node.
XmlNode -> Bool
children
Gets all child nodes of a node.
XmlNode -> List XmlNode
child-elements
Gets child element nodes only (skips text nodes).
XmlNode -> List XmlNode
find-child
Finds the first child element with a specific name.
XmlNode -> String -> Option XmlNode
find-children
Finds all child elements with a specific name.
XmlNode -> String -> List XmlNode
stringify
Converts a document to an XML string.
XmlDoc -> String
stringify-pretty
Converts a document to a formatted XML string.
XmlDoc -> String
doc
Creates an empty XML document.
() -> Result XmlDoc XMLError
element
Creates an element node with a specific tag name.
String -> Result XmlNode XMLError
set-root
Sets the root element of a document.
XmlDoc -> XmlNode -> Result () XMLError
add-child
Adds a child element to a parent node.
XmlNode -> String -> String -> Result XmlNode XMLError
set-attr
Sets an attribute on a node.
XmlNode -> String -> String -> Result () XMLError
set-text
Sets the text content of a node.
XmlNode -> String -> Result () XMLError
parse-root
Parses an XML string and returns document with root element.
String -> Result (XmlDoc, XmlNode) XMLError
build
Builds a simple XML document from a nested structure.
String -> List (String, String) -> Result XmlDoc XMLError