1 import std.array : appender; 2 3 auto writer = xmlWriter(appender!string()); 4 assert(writer.tagDepth == 0); 5 6 writer.writeStartTag("root", Newline.no); 7 assert(writer.tagDepth == 1); 8 assert(writer.output.data == "<root>"); 9 10 writer.writeStartTag("a"); 11 assert(writer.tagDepth == 2); 12 assert(writer.output.data == 13 "<root>\n" ~ 14 " <a>"); 15 16 // The tag depth is increased as soon as a start tag is opened, so 17 // any calls to writeIndent or writeAttr while a start tag is open 18 // will use the same tag depth as the children of the start tag. 19 writer.openStartTag("b"); 20 assert(writer.tagDepth == 3); 21 assert(writer.output.data == 22 "<root>\n" ~ 23 " <a>\n" ~ 24 " <b"); 25 26 writer.closeStartTag(); 27 assert(writer.tagDepth == 3); 28 assert(writer.output.data == 29 "<root>\n" ~ 30 " <a>\n" ~ 31 " <b>"); 32 33 writer.writeEndTag("b"); 34 assert(writer.tagDepth == 2); 35 assert(writer.output.data == 36 "<root>\n" ~ 37 " <a>\n" ~ 38 " <b>\n" ~ 39 " </b>"); 40 41 // Only start tags and end tags affect the tag depth. 42 writer.writeComment("comment"); 43 assert(writer.tagDepth == 2); 44 assert(writer.output.data == 45 "<root>\n" ~ 46 " <a>\n" ~ 47 " <b>\n" ~ 48 " </b>\n" ~ 49 " <!--comment-->"); 50 51 writer.writeEndTag("a"); 52 assert(writer.tagDepth == 1); 53 assert(writer.output.data == 54 "<root>\n" ~ 55 " <a>\n" ~ 56 " <b>\n" ~ 57 " </b>\n" ~ 58 " <!--comment-->\n" ~ 59 " </a>"); 60 61 writer.writeEndTag("root"); 62 assert(writer.tagDepth == 0); 63 assert(writer.output.data == 64 "<root>\n" ~ 65 " <a>\n" ~ 66 " <b>\n" ~ 67 " </b>\n" ~ 68 " <!--comment-->\n" ~ 69 " </a>\n" ~ 70 "</root>");
The current depth of the tag stack.