You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
12 lines
560 B
Racket
12 lines
560 B
Racket
10 years ago
|
#lang racket/base
|
||
|
(require xml racket/port racket/contract)
|
||
|
(provide (all-defined-out))
|
||
|
|
||
|
(define/contract (xml-string->xexprs str)
|
||
|
(string? . -> . (values xexpr? xexpr?))
|
||
|
(define xml-doc (with-input-from-string str (λ _ (permissive-xexprs #t) (read-xml))))
|
||
|
(values (xml->xexpr (document-prolog xml-doc)) (xml->xexpr (document-element xml-doc))))
|
||
|
|
||
|
(define/contract (xexprs->xml-string prolog-xexpr root-xexpr)
|
||
|
(xexpr? xexpr? . -> . string?)
|
||
|
(with-output-to-string (λ _ (write-xml (document (xexpr->xml prolog-xexpr) (xexpr->xml root-xexpr) null)))))
|