The given range with its front now at the end tag which corresponds to the parent start tag of the entity that was front when skipToParentEndTag was called. If the current entity does not have a parent start tag (which means that it's either the root element or a comment or PI outside of the root element), then an empty range is returned.
XMLParsingException on invalid XML.
1 auto xml = "<root>\n" ~ 2 " <foo>\n" ~ 3 " <!-- comment -->\n" ~ 4 " <bar>exam</bar>\n" ~ 5 " </foo>\n" ~ 6 " <!-- another comment -->\n" ~ 7 "</root>"; 8 { 9 auto range = parseXML(xml); 10 assert(range.front.type == EntityType.elementStart); 11 assert(range.front.name == "root"); 12 13 range.popFront(); 14 assert(range.front.type == EntityType.elementStart); 15 assert(range.front.name == "foo"); 16 17 range.popFront(); 18 assert(range.front.type == EntityType.comment); 19 assert(range.front.text == " comment "); 20 21 range = range.skipToParentEndTag(); 22 assert(range.front.type == EntityType.elementEnd); 23 assert(range.front.name == "foo"); 24 25 range = range.skipToParentEndTag(); 26 assert(range.front.type == EntityType.elementEnd); 27 assert(range.front.name == "root"); 28 29 range = range.skipToParentEndTag(); 30 assert(range.empty); 31 } 32 { 33 auto range = parseXML(xml); 34 assert(range.front.type == EntityType.elementStart); 35 assert(range.front.name == "root"); 36 37 range.popFront(); 38 assert(range.front.type == EntityType.elementStart); 39 assert(range.front.name == "foo"); 40 41 range.popFront(); 42 assert(range.front.type == EntityType.comment); 43 assert(range.front.text == " comment "); 44 45 range.popFront(); 46 assert(range.front.type == EntityType.elementStart); 47 assert(range.front.name == "bar"); 48 49 range.popFront(); 50 assert(range.front.type == EntityType.text); 51 assert(range.front.text == "exam"); 52 53 range = range.skipToParentEndTag(); 54 assert(range.front.type == EntityType.elementEnd); 55 assert(range.front.name == "bar"); 56 57 range = range.skipToParentEndTag(); 58 assert(range.front.type == EntityType.elementEnd); 59 assert(range.front.name == "foo"); 60 61 range.popFront(); 62 assert(range.front.type == EntityType.comment); 63 assert(range.front.text == " another comment "); 64 65 range = range.skipToParentEndTag(); 66 assert(range.front.type == EntityType.elementEnd); 67 assert(range.front.name == "root"); 68 69 assert(range.skipToParentEndTag().empty); 70 } 71 { 72 auto range = parseXML("<root><foo>bar</foo></root>"); 73 assert(range.front.type == EntityType.elementStart); 74 assert(range.front.name == "root"); 75 assert(range.skipToParentEndTag().empty); 76 }
Skips entities until the end tag is reached that corresponds to the start tag that is the parent of the current entity.