XMLWriter.writeCDATA

Writes a <![CDATA[...]]> section with the given text between the brackets.

  1. void writeCDATA(R text, Newline newline, InsertIndent insertIndent)
    struct XMLWriter(OR)
    void
    writeCDATA
    (
    R
    )
    if (
    isForwardRange!R &&
    isSomeChar!(ElementType!R)
    )
    if (
    isOutputRange!(OR, char)
    )
  2. void writeCDATA(R text, InsertIndent insertIndent, Newline newline)

Parameters

text R

The text of the CDATA section.

newline Newline

Whether a _newline followed by an indent will be written to the output range before the cdata section.

insertIndent InsertIndent

Whether an indent will be inserted after each _newline within the _text.

Throws

XMLWritingException if the given _text contains "]]>".

Examples

import std.array : appender;
import std.exception : assertThrown;

auto writer = xmlWriter(appender!string());

writer.writeStartTag("root", Newline.no);
writer.writeCDATA("see data run");
writer.writeCDATA("More data");
writer.writeCDATA("No preceding newline", Newline.no);
writer.writeCDATA("some data\nwith a newline");
writer.writeCDATA("Another newline\nbut no indent", InsertIndent.no);
writer.writeStartTag("tag");
writer.writeCDATA(" Deeper data <><> ");
writer.writeEndTag("tag");
writer.writeEndTag("root");

assert(writer.output.data ==
       "<root>\n" ~
       "    <![CDATA[see data run]]>\n" ~
       "    <![CDATA[More data]]><![CDATA[No preceding newline]]>\n" ~
       "    <![CDATA[some data\n" ~
       "        with a newline]]>\n" ~
       "    <![CDATA[Another newline\n" ~
       "but no indent]]>\n" ~
       "    <tag>\n" ~
       "        <![CDATA[ Deeper data <><> ]]>\n" ~
       "    </tag>\n" ~
       "</root>");

// ]]> is not legal in a CDATA section.
assertThrown!XMLWritingException(writer.writeCDATA("]]>"));

// Unchanged after an XMLWritingException is thrown.
assert(writer.output.data ==
       "<root>\n" ~
       "    <![CDATA[see data run]]>\n" ~
       "    <![CDATA[More data]]><![CDATA[No preceding newline]]>\n" ~
       "    <![CDATA[some data\n" ~
       "        with a newline]]>\n" ~
       "    <![CDATA[Another newline\n" ~
       "but no indent]]>\n" ~
       "    <tag>\n" ~
       "        <![CDATA[ Deeper data <><> ]]>\n" ~
       "    </tag>\n" ~
       "</root>");

See Also

Meta