-
Notifications
You must be signed in to change notification settings - Fork 22.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update: namespace crash course #27662
Conversation
Preview URLs Flaws (1)URL:
External URLs (5)URL:
(comment last updated: 2023-07-01 18:35:27) |
|
||
Note that namespace names are just strings, so the fact that the SVG namespace name also looks like a URI isn't important. URIs are commonly used because they are unique, the intention is not to "link" somewhere. (In fact URIs are used so frequently that the term "namespace URI" is commonly used instead of "namespace name".) | ||
Note that namespace names are just strings, so the fact that the SVG namespace name also looks like a URI isn't important. URIs are commonly used because they are unique, the intention is not to "link" somewhere. (In fact, URIs are used so frequently that the term "namespace URI" is commonly used instead of "namespace name".) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did not know that! I'd always wondered why rendering worked even if there was no fetch on the namespace URL.
@@ -64,11 +66,11 @@ XML dialects not only define their own elements, but also their own parameters. | |||
</svg> | |||
``` | |||
|
|||
This example has the rather unusual looking parameter `xmlns:xlink`. As you may guess from the first 'xmlns' part, this is another namespace declaration. However, instead of setting the default namespace, this namespace declaration sets the namespace for something called a "namespace prefix". In this case, we have chosen to use the prefix `xlink` (the second part) since the prefix will be used to tell the user agent about attributes that belong to XLink. | |||
This example has the rather unusual-looking parameter `xmlns:xlink`. As you may guess from the first `xmlns` part, this is another namespace declaration. However, instead of setting the default namespace, this namespace declaration sets the namespace for something called a "[namespace prefix](/en-US/docs/Web/API/CSSNamespaceRule/prefix)". In this case, we have chosen to use the prefix `xlink` (the second part) since the prefix will be used to tell the user agent about attributes that belong to `XLink`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just FWIW, the namespace prefix link to a css rule on an SVG example looks a bit odd when reading the source. My assumption is that you chose this link and it makes sense to a reader.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find this weird too, especially since the prefix
page is very brief as well.
|
||
As their name suggests, namespace prefixes are used to prefix parameter and element names. This is done by putting the namespace prefix and a colon before the parameter name as shown on the `<script>` element in the example above. This tells the user agent that the particular parameter belongs to the namespace assigned to the namespace prefix (XLink), and is a parameter that can be used with the same meaning on other elements. | ||
As their name suggests, namespace prefixes are used to prefix parameter and element names. This is done by putting the namespace prefix and a colon before the parameter name as shown on the `<script>` element in the example above. This tells the user agent that the particular parameter belongs to the namespace assigned to the namespace prefix (`XLink`), and is a parameter that can be used with the same meaning on other elements. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it the "same meaning on other elements"? I understand that it is the same name, just confirming that if the same name is used in multiple specs it means the same thing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is so much better. I've added some nits/suggestions. Approving so you can merge after whatever you choose to accept or not.
|
||
#### Redeclaring the default namespace | ||
|
||
So if all the descendants of the root element are also defined to be in the default namespace, how do you mix in content from another namespace? Easy. You just redefine the default namespace. Here's a short example. | ||
If all the descendants of the root element are also defined to be in the default namespace, how do you mix in content from another namespace? You redefine the default namespace! Here's a short example. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You redefine the default namespace!
In HTML, now the default namespaces are always implied and they are forced (you can't declare your own default namespace in the markup). So this entire section, from HTML point of view, has no utility left.
All it is doing now is asking developers to explicitly use xmlns
attributes, which is not required.
I say we either
- remove the section
Redeclaring the default namespace
completely - or make it discuss about XML, where it still applies:
<report xmlns="www.acme.org/reports> <title>Some stats</title> <summary>...</summary> <statTable xmlns="www.acme.org/tables> <content>...</content> <summary xmlns="www.acme.org/reports">...</summary> <!-- redeclaring root's default namespace --> </statTable> </report>
On MDN do we consider XML while discussing CSS? or just HTML?
Co-authored-by: Hamish Willee <hamishwillee@gmail.com>
|
||
See, namespaces really aren't that hard. | ||
This example was for illustrative purposes only. With HTML, `http://www.w3.org/1999/xhtml` is the implied namespace. It does not need to be explicitly declared. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This example was for illustrative purposes only. With HTML, `http://www.w3.org/1999/xhtml` is the implied namespace. It does not need to be explicitly declared. | |
This example was for illustrative purposes only. With HTML, `http://www.w3.org/1999/xhtml` is the implied namespace. It does not need to be explicitly declared. In HTML, the default namespaces are always implied and are forced, meaning you can't redeclare a different default namespace in the markup |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixing lint issues.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Grammar suggestions
Co-authored-by: Onkar Ruikar <87750369+OnkarRuikar@users.noreply.github.com>
Co-authored-by: Onkar Ruikar <87750369+OnkarRuikar@users.noreply.github.com>
Co-authored-by: Onkar Ruikar <87750369+OnkarRuikar@users.noreply.github.com>
Co-authored-by: Joshua Chen <sidachen2003@gmail.com>
Co-authored-by: Joshua Chen <sidachen2003@gmail.com>
Co-authored-by: Joshua Chen <sidachen2003@gmail.com>
Only added a single link to CSS namespace API. after namespace documentation is complete will add a few more links, but that is a future PR