Skip to content

Truly independent web browser

1.2 KB
Raw Blame
<!doctype html>
<script src="../include.js"></script>
<script>
    test(() => {
        const doc = new DOMParser().parseFromString(`<root xmlns:ex="https://example.test/ns"/>`, "application/xml");
        for (const fragment of [`<ex:child/>`, `<other:child/>`, `<xml:child/>`, `<child xmlns:xmlns="urn:x"/>`]) {
            try {
                doc.documentElement.innerHTML = fragment;
                println(`${fragment}: ${doc.documentElement.childNodes.length} child(ren)`);
            } catch (e) {
                println(`${fragment}: ${e.name}`);
            }
        }
        // The context element itself is the fragment's root, so a name the builder rejected there would leave the parse
        // with no document element at all; the xml prefix is bound by definition and has to resolve.
        const context = doc.createElementNS("http://www.w3.org/XML/1998/namespace", "xml:context");
        doc.documentElement.append(context);
        try {
            context.innerHTML = `<child/>`;
            println(`xml:context: ${context.childNodes.length} child(ren)`);
        } catch (e) {
            println(`xml:context: ${e.name}`);
        }
    });
</script>