1 import std.algorithm.comparison : equal; 2 import std.algorithm.iteration : filter; 3 { 4 auto xml = "<root/>"; 5 auto range = parseXML(xml); 6 assert(range.front.type == EntityType.elementEmpty); 7 assert(range.front.attributes.empty); 8 9 static assert(is(ElementType!(typeof(range.front.attributes)) == 10 typeof(range).Entity.Attribute)); 11 } 12 { 13 auto xml = "<root a='42' q='29' w='hello'/>"; 14 auto range = parseXML(xml); 15 assert(range.front.type == EntityType.elementEmpty); 16 17 auto attrs = range.front.attributes; 18 assert(attrs.front.name == "a"); 19 assert(attrs.front.value == "42"); 20 assert(attrs.front.pos == TextPos(1, 7)); 21 attrs.popFront(); 22 23 assert(attrs.front.name == "q"); 24 assert(attrs.front.value == "29"); 25 assert(attrs.front.pos == TextPos(1, 14)); 26 attrs.popFront(); 27 28 assert(attrs.front.name == "w"); 29 assert(attrs.front.value == "hello"); 30 assert(attrs.front.pos == TextPos(1, 21)); 31 attrs.popFront(); 32 33 assert(attrs.empty); 34 } 35 // Because the type of name and value is SliceOfR, == with a string 36 // only works if the range passed to parseXML was string. 37 { 38 auto xml = filter!(a => true)("<root a='42' q='29' w='hello'/>"); 39 auto range = parseXML(xml); 40 assert(range.front.type == EntityType.elementEmpty); 41 42 auto attrs = range.front.attributes; 43 assert(equal(attrs.front.name, "a")); 44 assert(equal(attrs.front.value, "42")); 45 assert(attrs.front.pos == TextPos(1, 7)); 46 attrs.popFront(); 47 48 assert(equal(attrs.front.name, "q")); 49 assert(equal(attrs.front.value, "29")); 50 assert(attrs.front.pos == TextPos(1, 14)); 51 attrs.popFront(); 52 53 assert(equal(attrs.front.name, "w")); 54 assert(equal(attrs.front.value, "hello")); 55 assert(attrs.front.pos == TextPos(1, 21)); 56 attrs.popFront(); 57 58 assert(attrs.empty); 59 }
Returns a lazy range of attributes for a start tag where each attribute is represented as a
$(PHOBOS_REF_ALTTEXT Tuple, Tuple, std, typecons)!( $(LREF2 SliceOfR, EntityRange), $(D_STRING "name"), $(LREF2 SliceOfR, EntityRange), $(D_STRING "value"), $(LREF TextPos), $(D_STRING "pos")).