9.2 XML Quote primitives
In most cases, the preferred way to create an XML document is to
create a Prolog tree of element(Name, Attributes, Content)
terms and call xml_write/3
to write this to a stream. There are some exceptions where one might not
want to pay the price of the intermediate representation. For these
cases, this library contains building blocks for emitting markup data.
The quote funtions return a version of the input text into one that
contains entities for characters that need to be escaped. These are the
XML meta characters and the characters that cannot be expressed by the
document encoding. Therefore these predicates accept an encoding
argument. Accepted values are ascii
,
iso_latin_1
, utf8
and unicode
.
Versions with two arguments are provided for backward compatibility,
making the safe
ascii
encoding assumption.
- xml_quote_attribute(+In, -Quoted, +Encoding)
- Map the characters that may not appear in XML attributes to entities.
Currently these are
<>&"
.4Older versions also mapped’
to'
. Characters that cannot represented in Encoding are mapped to XML character entities. - xml_quote_attribute(+In, -Quoted)
- Backward compatibility version for xml_quote_attribute/3.
Assumes
ascii
encoding. - xml_quote_cdata(+In, -Quoted, +Encoding)
- Very similar to xml_quote_attribute/3, but does not quote the single- and double-quotes.
- xml_quote_cdata(+In, -Quoted)
- Backward compatibility version for xml_quote_cdata/3.
Assumes
ascii
encoding. - xml_name(+In, +Encoding)
- Succeed if In is an atom or string that satisfies the rules for a valid XML element or attribute name. As with the other predicates in this group, if Encoding cannot represent one of the characters, this function fails. Character classification is based on http://www.w3.org/TR/2006/REC-xml-20060816.
- xml_name(+In)
- Backward compatibility version for xml_name/2.
Assumes
ascii
encoding.