You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
constpi=document.createProcessingInstruction("t","");pi.setAttribute("$","x");pi.getAttribute("$");// "x"pi.data=pi.data;pi.getAttribute("$");// null, and the whole map is now empty
$ isn't an XML NameStartChar, but processing-instruction-attributes.html requires setAttribute("$", …) to work. Names containing ", ', <, or & are allowed too, and they produce data that isn't well formed: pi.setAttribute('a"b', "x") gives a"b="x".
Clones and range copies run into the same problem if they reparse their data (see #1504).
There are lots of ways to use DOM APIs to produce trees that don't survive reparsing, and what we've done here is closer to the existing element.setAttribute(), which is nice for consistency. Those APIs are also for the XML syntax, after all.
However, that's not a solid argument. The way that PI attributes work isn't quite like anything else, so what should it be consistent with? Moreover, both data and the parsed attributes are always there and in sync, and you can stumble into roundtrip issues with the seemingly innocent pi.data += ' more="attributes"'.
Activity
annevk commentedon Nov 10, 2026
FWIW, my opinion is that since we decided to go with a strict parser, we should also be strict for the API and keep them 1:1.
noamr commentedon Nov 10, 2026
I think I'm OK with this. @foolip ?
foolip commentedon Nov 10, 2026
Here's the argument I was tempted to make:
However, that's not a solid argument. The way that PI attributes work isn't quite like anything else, so what should it be consistent with? Moreover, both
dataand the parsed attributes are always there and in sync, and you can stumble into roundtrip issues with the seemingly innocentpi.data += ' more="attributes"'.So yes, I'm OK with this!
Implement the ProcessingInstruction attribute API
Implement the ProcessingInstruction attribute API
Implement the ProcessingInstruction attribute API
Implement the ProcessingInstruction attribute API
Implement the ProcessingInstruction attribute API
Implement the ProcessingInstruction attribute API
Processing instruction attributes: test the grammar the parser follows
Implement the ProcessingInstruction attribute API