From eaccd20e227e80d1fb28e401c8ab06e6c206c0b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Koz=C3=A1k?= Date: Thu, 27 Jul 2017 16:10:02 +0200 Subject: [PATCH] FIX #41 "" parsed as if it were nothing --- source/std/experimental/xml/domparser.d | 28 +++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/source/std/experimental/xml/domparser.d b/source/std/experimental/xml/domparser.d index 69fe53b..0f0ef81 100644 --- a/source/std/experimental/xml/domparser.d +++ b/source/std/experimental/xml/domparser.d @@ -181,6 +181,8 @@ struct DOMBuilder(T, DOMImplementation = dom.DOMImplementation!(T.StringType)) { switch (cursor.kind) { + // XMLKind.elementEnd is needed for empty tags: + case XMLKind.elementEnd: case XMLKind.elementStart: case XMLKind.elementEmpty: auto elem = document.createElement(cursor.name); @@ -260,4 +262,30 @@ unittest assert(doc.getElementsByTagName("ccc").length == 1); assert(doc.documentElement.getAttribute("xmlns:myns") == "something"); +} + +unittest +{ + import std.experimental.xml.lexers; + import std.experimental.xml.parser; + import std.experimental.xml.cursor; + import std.experimental.allocator.gc_allocator; + import domimpl = std.experimental.xml.domimpl; + + alias DOMImplType = domimpl.DOMImplementation!string; + + auto xml = ``; + auto builder = + xml + .lexer + .parser + .cursor + .copyingCursor + .domBuilder(new DOMImplType()); + + builder.setSource(xml); + builder.buildRecursive; + auto doc = builder.getDocument; + + assert(doc.childNodes.length == 1); } \ No newline at end of file