AtlatestRepositorysigil-sxml
sigil-sxml / treeREADME.md
1
# sigil-sxml3
SXML processing library for [Sigil](https://codeberg.org/sigil/sigil). Convert between S-expression representations of XML/HTML and serialized markup strings.5
## Usage7
```scheme8
(import (sigil sxml))10
;; Convert SXML to HTML11
(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 automatically17
(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 XML27
```scheme28
(import (sigil sxml reader))30
;; Parse XML string to SXML31
(xml->sxml "<div class=\"main\"><p>Hello</p></div>")32
; => (div (@ (class "main")) (p "Hello"))34
;; Parse multiple top-level elements35
(xml->sxml* "<p>One</p><p>Two</p>")36
; => ((p "One") (p "Two"))37
```39
### Element Inspection41
```scheme42
(sxml-tag '(div (@ (class "box")) "content")) ; => div43
(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
## Features51
- **SXML to HTML** with automatic void element handling and text escaping52
- **SXML to XML** with self-closing element support53
- **XML parser** with streaming/incremental parsing support54
- **Element inspection** for querying tags, attributes, and content55
- **Raw HTML pass-through** via `(*raw* "...")` nodes57
## Dependencies59
- sigil-stdlib61
## Build63
```sh64
sigil build65
sigil test66
```68
## License70
BSD-3-Clause