Element.dup

Clone this element

struct Element
dup
(
bool deep = true
)

Examples

import std.array;
import std.algorithm : map;

Document doc = Document(`<html><p data-a="a" data-b="b"><i></i><b></b>`);
Element e = doc.byTagName("p").front;
Element f = e;
Element g = e.dup(false);
Element h = g;

assert(e!=g);
assert(f!=g);
assert(g==h);

assert(g.name == "p");
assert(g.attributes.array == [Attribute("data-a", "a"), Attribute("data-b", "b")]);
assert(g.descendants.map!(x=>x.name).array == []);

g = e.clone(true);
assert(g.name == "p");
assert(g.attributes.array == [Attribute("data-a", "a"), Attribute("data-b", "b")]);
assert(g.descendants.map!(x=>x.name).array == ["i", "b"]);

Meta