On this page:
read
write
from_  string
from_  bytes
to_  string
to_  bytes
current_  read_  normalize
current_  read_  comments
current_  read_  processing_  instructions
current_  read_  count_  bytes
current_  read_  collapse_  whitespace
current_  write_  empty_  shorthand
Indentation
Indentation.none
Indentation.peek
Indentation.scan
8.17.0.3

2 Reading and Writing XML🔗ℹ

function

fun xml.read(

  ~in: inp :: Port.Input = Port.Input.current(),

  ~read_post_misc: read_post_misc = #true

) :: xml.Document

 

function

fun xml.write(

  doc :: xml.Document || xml.Element,

  ~out: outp :: Port.Output = Port.Output.current(),

  ~indentation: indentation :: xml.Indentation = #'none

) :: Void

Reads an XML document into a xml.Document object or writes a xml.Document object as an XML document. Supplying a xml.Element object to xml.write is a shortcut for supplying a document that contains just the element.

The xml.read function normalizes input when the value of xml.current_read_normalize is #true. In that case, multiple consecutive xml.Text objects in content are collapsed into a single xml.Text object that has the xml.Text.WriteMode.default write mode.

By default, xml.write does not add newlines or other whitespace that is not explicitly present in doc. If indentation is #'scan, then whitespace is added within each element unless any content within the element (potentially nested in other elements) is a xml.PCData or xml.Entity. If indentation is #'peek, then printing is like #'scan, except that only the immediate content of an element is checked, and nested xml.PCData or xml.Entity do not disable whitespace.

function

fun xml.from_string(str :: String) :: xml.Document

 

function

fun xml.from_bytes(bstr :: Bytes) :: xml.Document

 

function

fun to_string(

  doc :: xml.Document || xml.Element,

  ~indentation: indentation :: Indentation = #'none

) :: String

 

function

fun xml.to_bytes(

  doc :: xml.Document || xml.Element,

  ~indentation: indentation :: Indentation = #'none

) :: Bytes

Shortcuts for xml.read and xml.write to read or write XML documents as strings or byte strings.

context parameter

Parameter.def xml.current_read_normalize :: Any.to_boolean:

  #true

Then this parameter’s value is #true, xml.read collapses consecutive text content to a xml.Text object.

context parameter

Parameter.def xml.current_read_comments :: Any.to_boolean:

  #false

Unless this parameter’s value is #true, xml.read discards comments.

When this parameter’s value is #false, xml.read discards processing instructions.

context parameter

Parameter.def xml.current_read_count_bytes :: Any.to_boolean:

  #false

If this parameter’s value is #true, xml.read counts by bytes for columns and offsets in source locations. If the parameter’s value if #false, xml.read counts by characters, instead.

If this parameter’s value is #true, xml.read collapses consecutive whitespace characters to a single space.

If this parameter’s value is #true, xml.write prints elements with empty content using <tag/>.

enumeration

enum xml.Indentation:

  none

  peek

  scan

Indentation modes for xml.write.