{"size": 1418, "ext": "scrbl", "max_stars_repo_path": "sugar/scribblings/xml.scrbl", "max_stars_repo_name": "mbutterick/sugar", "max_stars_repo_stars_event_min_datetime": "2015-04-13T15:10:18.000Z", "max_stars_repo_stars_event_max_datetime": "2020-03-21T06:05:14.000Z", "max_issues_repo_path": "sugar/scribblings/xml.scrbl", "max_issues_repo_name": "mbutterick/sugar", "max_issues_repo_issues_event_min_datetime": "2015-04-13T15:38:56.000Z", "max_issues_repo_issues_event_max_datetime": "2020-02-16T20:00:54.000Z", "max_forks_repo_path": "sugar/scribblings/xml.scrbl", "max_forks_repo_name": "mbutterick/sugar", "max_forks_repo_forks_event_min_datetime": "2015-04-13T13:41:00.000Z", "max_forks_repo_forks_event_max_datetime": "2016-08-13T17:02:00.000Z"}
{"max_stars_count": 16, "max_issues_count": 18, "max_forks_count": 5, "avg_line_length": 32.2272727273, "max_line_length": 246, "alphanum_fraction": 0.7313117066}
#lang scribble/manual

@(require scribble/eval (for-label racket sugar xml))

@(define my-eval (make-base-eval))
@(my-eval `(require sugar))

@title{XML}
@defmodule[#:multi (sugar/xml (submod sugar/xml safe))]


Making it easier to do the simplest kind of round-trip with XML: convert an XML string to X-expressions, manipulate, and then convert these X-expressions back to an XML string.

@defproc[
(xml-string->xexprs
[xml-string string?])
(values xexpr? xexpr?)]
Take a string containg XML and break it into two X-expressions: one representing the prolog of the document, and the other representing everything under the root node. Your @racket[_xml-string] must have a root node, but it doesn't need a prolog.

@examples[#:eval my-eval
(define str "<?xml encoding=\"utf-8\"?>\n<root>hello</root>")
(xml-string->xexprs str)
(define root-only "<root>hello</root>")
(xml-string->xexprs root-only)
(define prolog-only "<?xml encoding=\"utf-8\"?>")
(xml-string->xexprs prolog-only)
]


@defproc[
(xexprs->xml-string
[prolog-xexpr xexpr?]
[root-xexpr xexpr?])
string?]
Take two X-expressions representing the prolog and root of an XML document and join them back into an XML string. In other words, the inverse of the function above.

@examples[#:eval my-eval
(define str "<?xml encoding=\"utf-8\"?>\n<root>hello</root>")
(define-values (prolog doc) (xml-string->xexprs str))
prolog
doc
(xexprs->xml-string prolog doc)]

