Example 1 — Move a Namespaced Attr
Remove from XML, then set on a span (MDN-style move).
const ns = "http://www.example.com/ob";
const doc = new DOMParser().parseFromString(
'<warning ob:one="test" xmlns:ob="' + ns + '">Beware!</warning>',
"application/xml"
);
const span = document.querySelector("#demo");
const one = doc.querySelector("warning")
.attributes.removeNamedItemNS(ns, "one");
span.attributes.setNamedItemNS(one);
console.log(one.value); // "test" How It Works
- Parse XML. The attr lives in a real namespace URI.
- Remove it.
removeNamedItemNSfrees the Attr. - Set on the target.
setNamedItemNS(one)attaches it. - Read the value. The same Attr object now belongs to the span.

