Open wilzbach opened 6 years ago
From @NVolcz on October 18, 2016 21:24
unittest { import std.experimental.xml.lexers; import std.experimental.xml.parser; import std.string : lineSplitter, strip; import std.algorithm : map; import std.array : array; wstring xml = q{ <?xml encoding = "utf-8" ?> <!DOCTYPE mydoc> <aaa> <works> test </works> <notWork></notWork> </aaa> }; auto cursor = xml.lexer.parser.cursor; assert(cursor.atBeginning); // <?xml encoding = "utf-8" ?> assert(cursor.kind() == XMLKind.document); assert(cursor.name() == "xml"); assert(cursor.prefix() == ""); assert(cursor.localName() == "xml"); assert(cursor.attributes().array == [Attribute!wstring("encoding", "utf-8")]); assert(cursor.content() == " encoding = \"utf-8\" "); assert(cursor.enter()); assert(!cursor.atBeginning); // <!DOCTYPE mydoc assert(cursor.kind == XMLKind.dtdEmpty); assert(cursor.wholeContent == " mydoc"); assert(cursor.next); // <aaa> assert(cursor.kind() == XMLKind.elementStart); assert(cursor.name() == "aaa"); assert(cursor.prefix() == ""); assert(cursor.localName() == "aaa"); assert(cursor.enter()); // <works> assert(cursor.kind() == XMLKind.elementStart); assert(cursor.name() == "works"); assert(cursor.enter()); assert(!cursor.enter()); assert(!cursor.next()); //cursor.exit(); // </works> assert(cursor.kind() == XMLKind.elementEnd); assert(cursor.name() == "works"); cursor.exit(); assert(cursor.next()); // <notWork> assert(cursor.kind() == XMLKind.elementStart); assert(cursor.name() == "notWork"); assert(!cursor.enter()); assert(!cursor.next()); // </notWork> assert(cursor.kind() == XMLKind.elementEnd); assert(cursor.name() == "notWork"); assert(!cursor.next()); cursor.exit(); // </aaa> assert(cursor.kind() == XMLKind.elementEnd); assert(cursor.name() == "aaa"); assert(!cursor.next()); cursor.exit(); assert(cursor.documentEnd); assert(!cursor.atBeginning); }
Copied from original issue: lodo1995/experimental.xml#34
From @NVolcz on October 18, 2016 21:24
Copied from original issue: lodo1995/experimental.xml#34