• 0

xmlns?


Question

so, what's with this xmlns? I know it stands for: XML namespace. I know what namespace is and how to use it (C#, C++), however, I still don't know how to use xmlns.

So, why xmlns (I know it's used to escape collision with similiarly named tags)? and why it points out to a link? for example:

<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Dock Panel" Height="100" Width="400"
>

So each time I use this code, does it actually go to the provided link to validate or something? and how would it work if I had no Internet connection (given it actually goes to the target link). Could someone explain, I mean, really explain what's going on? Please, I need to know what's happening "in general" and not just in the said above example.

Thanks.

Link to comment
Share on other sites

5 answers to this question

Recommended Posts

  • 0

The W3C Recommendation (see Namespaces in Xml) is to use a URI as the value. the Xml parser wont visit that url, its just to sort any namespace conflicts, by assigning each of the used vocabularies a unique namespace. Quite often, when people use URLs as namespace declarations, they will put the schema definition at that address online for reference.

Link to comment
Share on other sites

  • 0

thanks for the answer, Antaris. However, I still cannot figure out *why*? If it does not visit the link, what's the point? Like you said, if I had the schema in the address, what's the point in using it since the application will never, ever, know about its existence?

Link to comment
Share on other sites

  • 0

ill just tell u wad i know about it in wpf

the first line declare a namespace for the global namespace to be used for the XML and the second for the x namespace, you can just ignore them but they are essential for WPF functionaility and define the vocab for the XAML syntax

Edited by Rejinderi
Link to comment
Share on other sites

  • 0

It is NOT a URL. It is a URI. Basically, to most XML parsers it's pretty much an arbitrary string. It just has to be unique for any given namespace.

URLs are a subset of URIs, so frequently people use a URL or URL-like string as a URI.

A common convention in XML is that the URI for a namespace will be an HTTP URL pointing to the XSD for the namespace. Using a URL with a domain owned by the creator of the namespace also reduces the chances of name collisions, and provides a hint to the ownership/authorship of the namespace.

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.