What has a namespace with XML?

Something bothers me:

The NSXMLParser method has the namespaceURI attribute:

- (void)parser:(NSXMLParser *)parser 
 didEndElement:(NSString *)elementName 
  namespaceURI:(NSString *)namespaceURI 
 qualifiedName:(NSString *)qName

From the documentation, I could not understand what they mean by "namespace". Can someone explain with an example what the namespace is in XML and why I would like this?

Edit: Yes, I noticed Wikipedia. But this is again confusing. What is the point of making a single namespace declaration at the top of an XML file, for example

xmlns:xhtml="http://www.w3.org/1999/xhtml"

?? Again, this only makes zero sense. There is no useful example on Wikipedia to get it, why I really would like a namespace and, more importantly, how it looks in an XML file. They say this to resolve the ambiguity of several of the same elements, such as an ID, but there is no example of how multiple namespaces can solve this.

+3
4

XML .

. URI node. () .

<!-- node without any namespace (it in the default namespace) -->
<node>
  <child /><!-- descendants are in the parent namespace by default -->
</node>

<!-- node with explicit default namespace -->
<node xmlns="http://some/namespace/uri/">
  <child /><!-- descendants are in the parent namespace by default -->
</node>

<!-- NS declaration with prefix (node is still in the default namespace!) -->
<node xmlns:prefix="http://some/namespace/uri/">
  <child /><!-- descendants are in the parent namespace -->
  <prefix:child><!-- explicit namespace assignment by prefix -->
    <grandchild /><!-- prefixes don't propagate, this is in the default namespace! -->
  </prefix:child>
</node>

. node . XML-, ( ).

<prefix:child />:

didEndElement = "child"
 namespaceURI = "http://some/namespace/uri/"
qualifiedName = "prefix:child"
+7

, XML. "" uri.

Tomalaks:

<!-- Mixing namespaces default namespace -->
<node xmlns:gc="http://other/namespace/gc"> <!-- node is in default NS -->
  <child> <!-- child is still in default NS, inherited from parent - node -->
    <gc:grandchild/>  <!-- grandchild is in the "http://other/namespace/gc", because of gc prefix -->
  </child>
  <child xmlns="http://some/namespace/uri/" xmlns:gc2="http://other/namespace/gc"> <!-- node is in "http://home/namespace/uri" because of declration -->
    <gc2:grandchild/> <!-- again, in "http://other/namespace/gc", despite different prefix -->
    <grandchild/> <!-- yet this one is in "http://home/namespace/uri", no prefix, inherited from parent -->
  </child>
</node>

, "" node - . , " " ". XSL.

. gc: grandchild gc2: grandchild THE SAME, URI , . node , node.

, " " xml . , SVG XHTML. node.

XML . .., .

SAML SOAP -. SOAP , SAML - , " XML". .

+3

XML, , local-name xml.

XML-, . , () :

<article>
  <head>
    <author>Emily Berthenstien</author>
  </head>
....

, , .

<citations>
  <citation>
    <author>Bernard Rightofen</author>
  </citation>  
</citations>       

2 "" ?

"" , QName ( XPath - ) . , , XPath QName:

declare namespace citauths="http://citation/authors/only"

//citauths:author

:

declare namespace auths="http://article/authors/only"

//auths:author
+1
source

Source: https://habr.com/ru/post/1732199/


All Articles