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

@annevk commented on this pull request.



> @@ -6005,11 +6005,15 @@ method steps are:
  "<code>?></code>", then <a>throw</a> an
  "{{InvalidCharacterError!!exception}}" {{DOMException}}. <!-- Gecko does this. -->
 
- <li>Return a new {{ProcessingInstruction}}
+ <li>Let <var>pi</var> be a new {{ProcessingInstruction}}

Let's fix this algorithm to use `<li><p>` as well.

> +<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>.

Do we really need to do this? Even for elements we only do this for HTML elements, not all of them.

> +<div algorithm>
+<p>To <dfn>update attributes from data</dfn> for a {{ProcessingInstruction}} <a for=/>node</a>
+<var>pi</var>:
+
+<ol>
+ <li><p><a for=map>Clear</a> <var>pi</var>'s <a for=ProcessingInstruction>attribute map</a>.
+
+ <li><p>Let <var>context</var> be the result of <a>creating an element</a> given
+ <var>pi</var>'s <a>node document</a>, "<code>html</code>", and the <a>HTML namespace</a>.
+
+ <li><p>Let <var>markup</var> be the concatentation of "<code>&lt;attrs </code>",
+ <var>pi</var>'s <a for=CharacterData>data</a>, and
+ "<code>&gt;&lt;/attrs&gt;</code>".
+
+ <li><p>Let <var>fragment</var> be the result of invoking the
+ <a>fragment parsing algorithm steps</a> with <var>context</var> and <var>markup</var>.

I don't think it's great that the parsing rules depend on the context document. I also don't see how this is handling errors in the XML case.

> @@ -6005,11 +6005,15 @@ method steps are:
  "<code>?></code>", then <a>throw</a> an
  "{{InvalidCharacterError!!exception}}" {{DOMException}}. <!-- Gecko does this. -->
 
- <li>Return a new {{ProcessingInstruction}}
+ <li>Let <var>pi</var> be a new {{ProcessingInstruction}}

But even better. We should make this algorithm invoke "initialize a ProcessingInstruction node" that essentially does what this algorithm does except for allocating a new node. Then we can reuse it for the constructor and keep them synchronized indefinitely.

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

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

Received on Friday, 6 March 2026 09:13:53 UTC