AtlatestRenderedmarkdown
Readme

sigil-sxml

SXML processing library for Sigil. Convert between S-expression representations of XML/HTML and serialized markup strings.

Usage

(import (sigil sxml))

;; Convert SXML to HTML
(sxml->html '(div (@ (class "main"))
               (h1 "Hello")
               (p "Welcome to " (strong "Sigil") ".")))
; => "<div class=\"main\"><h1>Hello</h1><p>Welcome to <strong>Sigil</strong>.</p></div>"

;; Void elements handled automatically
(sxml->html '(img (@ (src "photo.jpg"))))
; => "<img src=\"photo.jpg\">"

;; Convert SXML to XML (self-closing void elements)
(sxml->xml '(item (@ (id "1")) "Content"))
; => "<item id=\"1\">Content</item>"

Parsing XML

(import (sigil sxml reader))

;; Parse XML string to SXML
(xml->sxml "<div class=\"main\"><p>Hello</p></div>")
; => (div (@ (class "main")) (p "Hello"))

;; Parse multiple top-level elements
(xml->sxml* "<p>One</p><p>Two</p>")
; => ((p "One") (p "Two"))

Element Inspection

(sxml-tag '(div (@ (class "box")) "content"))       ; => div
(sxml-attributes '(div (@ (id "main")) "text"))      ; => ((id "main"))
(sxml-content '(div (@ (id "main")) "hello" "world")) ; => ("hello" "world")
(sxml-attr-ref '(div (@ (id "main"))) 'id)           ; => "main"
(sxml-attr-set '(div "text") 'id "main")             ; => (div (@ (id "main")) "text")

Features

  • SXML to HTML with automatic void element handling and text escaping
  • SXML to XML with self-closing element support
  • XML parser with streaming/incremental parsing support
  • Element inspection for querying tags, attributes, and content
  • Raw HTML pass-through via (*raw* "...") nodes

Dependencies

  • sigil-stdlib

Build

sigil build
sigil test

License

BSD-3-Clause