Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between namespace in XML

I'm creating XML document using XDocument in C#. I have a question.

Is

<Simple xmlns = "Example"></Simple>

equivalent to

<Example:Simple></Example:Simple>

?

I tried to get second solution with XNamespace and XElement in C#, but I get only first.

like image 214
GrzesiekO Avatar asked Nov 24 '25 10:11

GrzesiekO


1 Answers

No.

The first example creates a Simple element in the Example namespace (note that namespaces are usually expressed as URIs)

The second example creates a Simple element in whatever namespace is associated with the Example prefix (as defined by an xmlns attribute).

These would be equivalent:

<xml xmlns="http://example.com/myNameSpace">
    <Simple></Simple>
</xml>

<xml xmlns="http://example.com/myNameSpace" xmlns:Example="http://example.com/myNameSpace">
    <Example:Simple></Example:Simple>
</xml>
like image 160
Quentin Avatar answered Nov 26 '25 00:11

Quentin