XMLWriter.writeEndTag

Writes an end tag to the output range with the name of the start tag that was most recently written and does not yet have a matching end tag.

If a name is provided, then it will be validated against the matching start tag.

  1. void writeEndTag(string name, Newline newline)
    struct XMLWriter(OR)
    void
    writeEndTag
    if (
    isOutputRange!(OR, char)
    )
  2. void writeEndTag(Newline newline)

Parameters

name string

Name to check against the matching start tag.

newline Newline

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

Throws

XMLWritingException if no start tag is waiting for a matching end tag or if the given _name does not match the _name of the start tag that needs to be matched next.

Examples

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

auto writer = xmlWriter(appender!string());
writer.writeStartTag("root", Newline.no);
assert(writer.output.data == "<root>");

writer.writeStartTag("foo");
assert(writer.output.data ==
       "<root>\n" ~
       "    <foo>");

// Name doesn't match start tag, which is <foo>.
assertThrown!XMLWritingException(writer.writeEndTag("bar"));

// Unchanged after an XMLWritingException is thrown.
assert(writer.output.data ==
       "<root>\n" ~
       "    <foo>");

writer.writeEndTag("foo", Newline.no);
assert(writer.output.data ==
       "<root>\n" ~
       "    <foo></foo>");

writer.writeStartTag("bar");
assert(writer.output.data ==
       "<root>\n" ~
       "    <foo></foo>\n" ~
       "    <bar>");

writer.writeEndTag("bar");
assert(writer.output.data ==
       "<root>\n" ~
       "    <foo></foo>\n" ~
       "    <bar>\n" ~
       "    </bar>");

// No name is required, but if it is not provided, then the code cannot
// validate that it's writing the end tag that it thinks it's writing.
writer.writeEndTag();
assert(writer.output.data ==
       "<root>\n" ~
       "    <foo></foo>\n" ~
       "    <bar>\n" ~
       "    </bar>\n" ~
       "</root>");

See Also

Meta