4 ms·
I never saw a nice use-case of namespaces. Maybe you can show me one? So far I have only seen namespaces used by Inkscape to state that a SVG is a still image
by legulere 9y ago
I never saw a nice use-case of namespaces. Maybe you can show me one?
So far I have only seen namespaces used by Inkscape to state that a SVG is a still image using 3 different name-spaces in one hierarchy. Does it not just add complexity to need to support different standards at the same time
- barrkel 9y agoIf you ever have to annotate one tree using a completely separate tool, you need to do something to ensure the names you choose are different from the ones used by whatever produces the tree. You can choose odd names, but there's no guarantee. Namespaces can provide that guarantee, via uniqueness of URIs, ultimately relying ICANN.
- btschaegg 9y agoAlmost certain this doesn't qualify as "nice", but: Namespaces make XSLT more powerful than one might think at first, because they allow you to write XSLT that generates XSLT (and so on...) by switching a namespace to a different one upon output generation. Of course, the result is often barely readable anymore, so there's that. Edit: On the other hand, the difference between XSLT-namespaced elements and all the others in a stylesheet is the one thing that makes basic XSLT readable, since you don't have to use a full meta-language just to create simple elements.
- josteink 9y ago> I never saw a nice use-case of namespaces. Maybe you can show me one? Basic example: If you want to mix data from several formats in one document. Let's say you want to create an RSS-feed which contains information about "new stuff" whatever that new stuff is. This "new stuff" may actually be other XML-data which can be parseable and processable by other tools (like for instance new builds, deployments, whatever). This data probably has a format of sorts individually, independent of the RSS-feed itself, which has its own well defined format. Now let's say both the RSS-feed and the custom-data contains both a "link" element and a "title" element. Without namespaces, these are bound to collide. Some examples of problems which then arises: - How can a RSS-library validate that the feed format itself is correct? - How does a RSS-feed library know which "link" elements it should process and display, instead of only ones which belongs to the feed definition? - How does the RSS-processing library know that it should most definitely ignore that title which belongs to the deployment metadata? - Etc etc Namespaces allows you to combine data from different formats without ever running the risk of the data getting mixed up by whoever consumes them. It's a really basic feature, and it's at the core of the whole eXtensible bit of XML. I'm honestly surprised by both the amount of people who find this confusing and how few people are able to realize the value of such a simple construct. I guess too many "1337 HTML ninja rockstars" got introduced to XML as "just another angle-bracket markup format" and never actually bothered to learn anything about absolutely foundational XML basics.
- legulere 9y ago> Basic example: If you want to mix data from several formats in one document. Can you get more concrete on why you would want to mix formats? So far what I have seen namespaces were used just to extend one format. > Now let's say both the RSS-feed and the custom-data contains both a "link" element and a "title" element. Easily avoided if you just extend one format, but can happen if you would want to mix existing formats because of some reason. > - How can a RSS-library validate that the feed format itself is correct? You still need some code that parses the non-RSS part anyway, which can validate it. Don't you usually have just one parser that parses RSS and the non-RSS at the same time? If not, how are you passing your non-RSS XML tree-parts from the RSS-only library to the "new stuff"?
- josteink 9y ago> You still need some code that parses the non-RSS part anyway, which can validate it. Provenly incorrect. How many RSS validators validates the contained HTML (as HTML, not as per XML well-formedness)?