Re: [whatwg/dom] Define processing instruction attributes (PR #1454)

@foolip commented on this pull request.



> +<a for=map>is empty</a>; otherwise true.
+</div>
+
+<div algorithm>
+<p>The <dfn method for=ProcessingInstruction><code>getAttributeNames()</code></dfn> method steps
+are to return the result of <a for=map>getting the keys</a> of <a>this</a>'s
+<a for=ProcessingInstruction>attribute map</a>.
+</div>
+
+<div algorithm>
+<p>The <dfn method for=ProcessingInstruction><code>getAttribute(<var>name</var>)</code></dfn> method
+steps are:
+
+<ol>
+ <li><p>If <a>this</a>'s <a for=Node>node document</a> is an <a>HTML document</a>, then set
+ <var>name</var> to <var>name</var> in <a>ASCII lowercase</a>.

We're not constrained by web compat, only by what we think would be most consistent and least surprising to developers.

This was based on [get an attribute by name](https://dom.spec.whatwg.org/#concept-element-attributes-get-by-name) and would make the behavior very close to element attributes, assuming that we use the HTML parser to parse attributes in HTML documents. That behavior is:
- In HTML documents, the parser lowercases attribute names, and `getAttribute()` etc. all lowercase the input before looking for an exact match.
- With a PI imported from an XML document into an HTML document, `getAttribute()` would be unable to get the value of a camel-cased attribute.

However, we don't have the *NS variants that avoid the lowercasing, which would make camel-cased attributes from an XML parser inaccessible if moved to an HTML document. That's not great.

The simplest fix I can see is to just never lowercase the input, at the expense of `pi.getAttribute('NAME')` working differently from `element.getAttribute('NAME')` in an HTML document.

We also have the option of always lowercasing attribute names. That's tied to the discussion of which parser to use, in the next comment.

-- 
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/dom/pull/1454#discussion_r2905584656
You are receiving this because you are subscribed to this thread.

Message ID: <whatwg/dom/pull/1454/review/3915587381@github.com>

Received on Monday, 9 March 2026 13:55:56 UTC