|(require xml)||package: base|
The xml library does not provide Document Type Declaration (DTD) processing, including preservation of DTDs in read documents, or validation. It also does not expand user-defined entities or read user-defined entities in attributes. It does not interpret namespaces either.
#:extra-constructor-name make-location) line : (or/c false/c exact-nonnegative-integer?) char : (or/c false/c exact-nonnegative-integer?) offset : exact-nonnegative-integer?
#:extra-constructor-name make-source) start : location/c stop : location/c
(struct external-dtd (system) #:extra-constructor-name make-external-dtd) system : string?
(struct external-dtd/public external-dtd (public) #:extra-constructor-name make-external-dtd/public) public : string?
(struct external-dtd/system external-dtd () #:extra-constructor-name make-external-dtd/system)
(struct document-type (name external inlined) #:extra-constructor-name make-document-type) name : symbol? external : external-dtd? inlined : false/c
#:extra-constructor-name make-prolog) misc : (listof misc/c) dtd : (or/c document-type false/c) misc2 : (listof misc/c)
#:extra-constructor-name make-element) name : symbol? attributes : (listof attribute?) content : (listof content/c)
#:extra-constructor-name make-attribute) name : symbol? value : (or/c string? permissive/c)
#:extra-constructor-name make-entity) text : (or/c symbol? valid-char?)
The following grammar describes expressions that create X-expressions:
||||(list symbol (list (list symbol string) ...) xexpr ...)|
||||(cons symbol (list xexpr ...))|
A string is literal data. When converted to an XML stream, the characters of the data will be escaped as necessary.
A pair represents an element, optionally with attributes. Each attribute’s name is represented by a symbol, and its value is represented by a string.
A symbol represents a symbolic entity. For example, 'nbsp represents .
An valid-char? represents a numeric entity. For example, #x20 represents  .
|(require xml/xexpr)||package: base|
Malformed xml is reported with source locations in the form ‹l›.‹c›/‹o›, where ‹l›, ‹c›, and ‹o› are the line number, column number, and next port position, respectively as returned by port-next-location.
Any non-characters other than eof read from the input-port appear in the document content. Such special values may appear only where XML content may. See make-input-port for information about creating ports that return non-character values.
> (xml->xexpr (document-element (read-xml (open-input-string "<doc><bold>hi</bold> there!</doc>"))))
'(doc () (bold () "hi") " there!")
content : content/c out : output-port? = (current-output-port)
content : content/c out : output-port? = (current-output-port)
(write-xexpr xe [ out #:insert-newlines? insert-newlines?]) → void? xe : xexpr/c out : output-port? = (current-output-port) insert-newlines? : any/c = #f
If insert-newlines? is true, the X-expression is written with newlines before the closing angle bracket of a tag.
The escaping performed for attribute strings is slightly different from that performed for body strings, in that double-quotes must be escaped, as they would otherwise terminate the enclosing string.
Note that this conversion is performed automatically in attribute positions by xexpr->string, and you are therefore unlikely to need this function unless you are using include-template to insert strings directly into attribute positions of HTML.
Added in version 220.127.116.11 of package base.
> (validate-xexpr '(doc () "over " (em () "9000") "!"))
> (validate-xexpr #\newline)
Expected a string, symbol, valid numeric entity, comment,
processing instruction, or list, given #\newline
When the parameter is set to 'always, the abbreviated notation is always used. When set of 'never, the abbreviated notation is never generated. when set to a list of symbols is provided, tags with names in the list are abbreviated.
The abbreviated form is the preferred XML notation. However, most browsers designed for HTML will only properly render XHTML if the document uses a mixture of the two formats. The html-empty-tags constant contains the W3 consortium’s recommended list of XHTML tags that should use the shorthand. This list is the default value of empty-tag-shorthand.
> (parameterize ([empty-tag-shorthand html-empty-tags]) (write-xml/content (xexpr->xml `(html (body ((bgcolor "red")) "Hi!" (br) "Bye!")))))
<html><body bgcolor="red">Hi!<br />Bye!</body></html>
You may want to use #t if, for example, you will be communicating these offsets to a C program that can more easily deal with byte offsets into the character stream, as opposed to UTF-8 character offsets.
(xexpr-drop-empty-attributes drop?) → void? drop? : any/c
|(require xml/plist)||package: base|
The xml/plist library provides the ability to read and write XML documents that conform to the plist DTD, which is used to store dictionaries of string–value associations. This format is used by Mac OS X (both the operating system and its applications) to store all kinds of data.
||||(list 'integer integer)|
||||(list 'real real)|
||||(list 'data string)|
||||(list 'date string)|
||||(list 'array pl-expr ...)|
|dict-expr||=||(list 'dict assoc-pair ...)|
|assoc-pair||=||(list 'assoc-pair string pl-expr)|
> (define my-dict `(dict (assoc-pair "first-key" "just a string with some whitespace") (assoc-pair "second-key" (false)) (assoc-pair "third-key" (dict)) (assoc-pair "fourth-key" (dict (assoc-pair "inner-key" (real 3.432)))) (assoc-pair "fifth-key" (array (integer 14) "another string" (true))) (assoc-pair "sixth-key" (array)) (assoc-pair "seventh-key" (data "some data")) (assoc-pair "eighth-key" (date "2013-05-10T20:29:55Z")))) > (define-values (in out) (make-pipe)) > (write-plist my-dict out) > (close-output-port out) > (define new-dict (read-plist in)) > (equal? my-dict new-dict)
The XML generated by write-plist in the above example looks like the following, if re-formatted by hand to have newlines and indentation:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist SYSTEM
<string>just a string with some whitespace</string>
|(require xml/path)||package: base|
This library provides a simple path query library for X-expressions.
The prefix of symbols specifies a path of tags from the leaves with an implicit any sequence to the root. The final, optional keyword specifies an attribute.
> (define some-page '(html (body (p ([class "awesome"]) "Hey") (p "Bar")))) > (se-path*/list '(p) some-page)
> (se-path* '(p) some-page)
> (se-path* '(p #:class) some-page)
> (se-path*/list '(body) some-page)
'((p ((class "awesome")) "Hey") (p "Bar"))
> (se-path*/list '() some-page)
'((html (body (p ((class "awesome")) "Hey") (p "Bar")))
(body (p ((class "awesome")) "Hey") (p "Bar"))
(p ((class "awesome")) "Hey")