What are namespaces in XML?

Asked

Viewed 585 times

9

Well, I understand the concept of namespaces in C#, C++, etc.

But I don’t understand the concept of namespaces in WPF (XAML).

I’ve been trying to understand the parameters xmlns in a XAML code. I read MSDN publications on the subject but honestly still do not understand the concept of namespaces in XML.

  • You have some specific doubt, because if you already know how it is in C#/C++, you already know almost everything you need to know, basically it has a different syntax. I mean, I’m finding the question a little broad.

  • My knowledge of XML is very little. But I know that namespaces in C# and C++ for example have the purpose of avoiding name conflicts. What is the purpose of XML namespaces? And pq usually point to a URL address? Temalso wanted to understand the syntax xmlns:anyLetter

1 answer

7


In essence the purpose is to avoid conflict of names too, equal to the namespace C# or C++. The declaration and import syntax is different, but it works analogously (not identical). It remains only one surname for its members.

The idea came from XML. There was a little more sense to use Uris, after all it is used for data exchange with third parties and the chance of two names of the own namespace conflict is very big. What is the way to ensure that your namespace is unique? Use a name that you have control over, that no one else can use the same one (not that there is a ban, but there is a convention, those who do not follow want trouble). A name you have control of is a URI with your internet domain. And it’s just that, a name.

Because there is a URI many people think that it serves to connect on the internet and pick something up. Nothing! It is only a descriptive text, nothing prevents you from using something else, but then the risk of conflict becomes greater.

In XAML, which is used in a more restricted environment, the chance is much lower, yet there is a risk when using third-party components. Anyway it kept the XML convention.

Often this is a mapping with the namespace code C#. Example:

clr-namesapce:System.Collections;assembly=mscorlib

I’ll leave some references that I may not have read and should help:

If you have other more specific questions you can go doing individually.

  • Here in my WPF project, the XAML code has several namespaces. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:Views" Each of these is a namespace? If they are, one would not be enough?

  • 1

    Each statement of this has a different usage feature, note that there is a prefix in each indicating what it serves. Some are for specific tools. In this case one would not be enough, because they have different functions. But don’t think you are creating namespaces different. You have to see what each one means. It’s confusing even :) e.g. https://msdn.microsoft.com/en-us/library/aa350024(v=vs.110). aspx,

Browser other questions tagged

You are not signed in. Login or sign up in order to post.