XML: attributes and namespaces - no clear solution

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

XML: attributes and namespaces - no clear solution

Misha.Wolf

Dear XML Core WG,

 

Please would you be kind enough to advise on this conundrum.

 

Many thanks,

Misha

 

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Michael Steidl (IPTC)
Sent: 27 June 2011 12:10
To: [hidden email]
Subject: [IPTC-NAR-dev] XML: attributes and namespaces - no clear solution

 



This posting refers to the discussion on the NAR-dev conference call last Friday, 24 June. The issue was: do attributes inherit the namespace of its element and this way also default namespaces?

 

After some searching my findings are:

 

** [1] is the standard document of the W3C and it speaks about Applying Namespaces to Elements and Attributes (chapter 6) :

- 6.1 Namespace scoping:

“ The scope of a namespace declaration declaring a prefix extends from the beginning of the start-tag in which it appears to the end of the corresponding end-tag, excluding the scope of any inner declarations with the same NSAttName part. In the case of an empty tag, the scope is the tag itself.

Such a namespace declaration applies to all element and attribute names within its scope whose prefix matches that specified in the declaration.”

With this example:

<?xml version="1.0"?>

<html:html xmlns:html='http://www.w3.org/1999/xhtml'>

  <html:head><html:title>Frobnostication</html:title></html:head>

  <html:body><html:p>Moved to

    <html:a href='http://frob.example.com'>here.</html:a></html:p></html:body>

</html:html>

 

- 6.2 Namespace defaulting

The scope of a default namespace declaration extends from the beginning of the start-tag in which it appears to the end of the corresponding end-tag, excluding the scope of any inner default namespace declarations. In the case of an empty tag, the scope is the tag itself.

A default namespace declaration applies to all unprefixed element names within its scope. Default namespace declarations do not apply directly to attribute names; the interpretation of unprefixed attributes is determined by the element on which they appear.”

 

This leaves open what “determined by the element” exactly means – what we discussed last Friday: does the attribute inherit the element’s namespace – or not.

The next paragraph tells:

“ .... The namespace name for an unprefixed attribute name always has no value. ...”

 

... hm, this does not explain what “determined by the element” exactly means (Btw: the Errata document for this document says no errata exist ...). And there is no note available for the example above explaining if the  @href pertains to the html: namespace or not.

 

** So I started to google for views on that issue:

* The German  page (but not the one in English) about XML namespaces talks explicitly about attributes [2] – in short: as attributes are not a child node of an element they never inherit its namespace, if one wants to apply a namespace the corresponding prefix has to be applied.

* A website with “Articles and tutorials about XML-technology” [3] says about this issue: “An attribute is not considered a child of its parent element. An attribute never inherits the namespace of its parent element.”

* A VB tutorial about XML namespaces asserts the same [4]

* The only contradiction I found is on Stackoverflow [5]

“There's a reason that most XML vocabularies use non-namespaced attributes:

When your elements have a namespace and those elements have attributes, then there can be no confusion: the attributes belong to your element, which belongs to your namespace. Adding a namespace prefix to the attributes would just make everything more verbose.

So why do namespaced attributes exist?

Because some vocabularies do useful work with mostly attributes, and can do this when mixed in with other vocabularies.”

 

Conclusion:

-          W3C does not define how default namespaces apply to attributes in a straightforward way

-          It is not fully clear if an attribute of a namespaced element interits its namespace.

-          Published views on that matter lean towards “does not inherit” – but not unambiguously

 

What’s next: asking one of the editors of this document – Tim Bray or Henry Thompson?

 

Michael

 

[1] http://www.w3.org/TR/xml-names/

[2] http://de.wikipedia.org/wiki/Namensraum_%28XML%29#Attribute

[3] http://www.xmlplease.com/attributexmlns

[4] http://www.developerfusion.com/article/3720/understanding-xml-namespaces/6/

[5] http://stackoverflow.com/questions/41561/xml-namespaces-and-attributes

 

Michael Steidl

Managing Director of the IPTC [[hidden email]]

International Press Telecommunications Council
Web:
www.iptc.org - on Twitter @IPTC

Business office address:

20 Garrick Street, London WC2E 9BT, United Kingdom

Registered in England, company no 101096

 



__._,_.___

Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required)
Change settings via email: [hidden email] | [hidden email]
Visit Your Group | Yahoo! Groups Terms of Use | [hidden email]

 

__,_._,___


This email was sent to you by Thomson Reuters, the global news and information company. Any views expressed in this message are those of the individual sender, except where the sender specifically states them to be the views of Thomson Reuters.
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: XML: attributes and namespaces - no clear solution

Henry S. Thompson
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

A brief but partial response, as a full one will take some time.

1) Unprefixed attributes are never in a namespace.

2) The intention of the phrase "determined by the element" is that
   given an unprefixed attribute the _semantics_ of that attribute are
   the responsibility of its owner element.

   Thus in e.g. <person title=...> and <book title=...>
   the title attribute may receive very different interpretations.

   'person' and or 'book' may be in a namespace, in which case you
   have a good idea of where to look for information about those
   elements and, in turn, their unprefixed attributes.

Hope this helps.

ht
- --
       Henry S. Thompson, School of Informatics, University of Edinburgh
      10 Crichton Street, Edinburgh EH8 9AB, SCOTLAND -- (44) 131 650-4440
                Fax: (44) 131 651-1426, e-mail: [hidden email]
                       URL: http://www.ltg.ed.ac.uk/~ht/
 [mail from me _always_ has a .sig like this -- mail without it is forged spam]
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.6 (GNU/Linux)

iD8DBQFODf9BkjnJixAXWBoRAk9nAJ9AbKUWSCiVgcZBS9McgIy8eMgY/gCfW4nM
v1ElgodQme19/T5PZiTzvF8=
=Qkt5
-----END PGP SIGNATURE-----

Loading...