Download CDuce Programming Language User`s manual

Transcript
print_xml: Any -> Latin1
print_xml_utf8: Any -> String
They fail if the argument is not an XML document (this isn't checked statically). The
first operator print_xml prepares the document to be dumped to a ISO-8859-1
encoded XML file: Unicode characters outside Latin1 are escaped accordingly, and
the operator fails if the document contains tag or attribute names which cannot be
represented in ISO-8859-1. The second operator print_xml_utf8 always succeed
but produces a string suitable for being dumped in an UTF-8 encoded file. See the
variants of the dump_to_file operator in the section on Input/output.
In both cases, the resulting string does not contain the XML prefix "<?xml ...>".
Projection
The projection takes a sequence of XML elements and returns the concatenation of
all their children with a given type. The syntax is:
e/t
which is equivalent to:
transform e with <_>[ (x::t | _)* ] -> x
For instance, the expression [ <a>[ <x>"A" <y>"B"
<x>"D"] ] / <x>_ evaluates to [ <x>"A" <x>"D" ] .
]
<b>[
<y>"C"
There is another form of projection to extract attributes:
e/@l
which is equivalent to:
transform e with <_ l=l>_ -> l
The dot notation can also be used to extract the value of the attribute for one XML
element:
# <a x=3>[].x;;
- : 3 = 3
Iteration over XML trees
Another XML-specific construction is xtransform which is a generalization of
transform to XML trees:
25