dlang-community / experimental.xml

A replacement of Phobos std.xml
https://rawgit.com/dlang-community/experimental.xml/gh-pages/index.html
Boost Software License 1.0
11 stars 8 forks source link

"<tag></tag>" parsed as if it were nothing #16

Open wilzbach opened 6 years ago

wilzbach commented 6 years ago

From @jmdavis on January 6, 2017 8:20

This test fails

auto xml = `<?xml version="1.0" encoding="UTF-8"?><tag></tag>`;
auto domBuilder = lexer(xml).parser().cursor().domBuilder();
domBuilder.buildRecursive();
auto dom = domBuilder.getDocument();
assert(dom.childNodes.length == 1); // length is actually 0

This succeeds

auto xml = `<?xml version="1.0" encoding="UTF-8"?><tag/>`;
auto domBuilder = lexer(xml).parser().cursor().domBuilder();
domBuilder.buildRecursive();
auto dom = domBuilder.getDocument();
assert(dom.childNodes.length == 1);

as does this

auto xml = `<?xml version="1.0" encoding="UTF-8"?><tag>foo</tag>`;
auto domBuilder = lexer(xml).parser().cursor().domBuilder();
domBuilder.buildRecursive();
auto dom = domBuilder.getDocument();
assert(dom.childNodes.length == 1);

Also, adding attributes to the opening tag in the first example has no effect. It still fails.

So, something funny is going on when there's an open and closing tag with nothing between them, and attributes don't seem to have any impact on what's going on.

Copied from original issue: lodo1995/experimental.xml#41