AtlatestRepositorysigil-sxml
1# sigil-sxml
2
3SXML processing library for [Sigil](https://codeberg.org/sigil/sigil). Convert between S-expression representations of XML/HTML and serialized markup strings.
4
5## Usage
6
7```scheme
8(import (sigil sxml))
9
10;; Convert SXML to HTML
11(sxml->html '(div (@ (class "main"))
12 (h1 "Hello")
13 (p "Welcome to " (strong "Sigil") ".")))
14; => "<div class=\"main\"><h1>Hello</h1><p>Welcome to <strong>Sigil</strong>.</p></div>"
16;; Void elements handled automatically
17(sxml->html '(img (@ (src "photo.jpg"))))
18; => "<img src=\"photo.jpg\">"
20;; Convert SXML to XML (self-closing void elements)
21(sxml->xml '(item (@ (id "1")) "Content"))
22; => "<item id=\"1\">Content</item>"
23```
25### Parsing XML
27```scheme
28(import (sigil sxml reader))
30;; Parse XML string to SXML
31(xml->sxml "<div class=\"main\"><p>Hello</p></div>")
32; => (div (@ (class "main")) (p "Hello"))
34;; Parse multiple top-level elements
35(xml->sxml* "<p>One</p><p>Two</p>")
36; => ((p "One") (p "Two"))
37```
39### Element Inspection
41```scheme
42(sxml-tag '(div (@ (class "box")) "content")) ; => div
43(sxml-attributes '(div (@ (id "main")) "text")) ; => ((id "main"))
44(sxml-content '(div (@ (id "main")) "hello" "world")) ; => ("hello" "world")
45(sxml-attr-ref '(div (@ (id "main"))) 'id) ; => "main"
46(sxml-attr-set '(div "text") 'id "main") ; => (div (@ (id "main")) "text")
47```
49## Features
51- **SXML to HTML** with automatic void element handling and text escaping
52- **SXML to XML** with self-closing element support
53- **XML parser** with streaming/incremental parsing support
54- **Element inspection** for querying tags, attributes, and content
55- **Raw HTML pass-through** via `(*raw* "...")` nodes
57## Dependencies
59- sigil-stdlib
61## Build
63```sh
64sigil build
65sigil test
66```
68## License
70BSD-3-Clause