473,397 Members | 1,985 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Whose attributes are they anyway?

Hi,

I just can't find namespaces of attributes stated clearly enough in the
XML namespace spec.
But .. I hear rumors that attributes, unless qualified otherwise,
default to the namespace of the owner element.
Is that right ?

Like:

<?xml version='1.0'?>

<!-- I would think that the "odor" attribute below should belong to the
"smelly->http://www.stench.com"
name space, as its owner element is in that? The irrelevant:odor
attribute, of course, is in
the irrelevant->http://sweetaroma.org namespace ... right? -->

<smelly:skunk
xmlns:smelly="http://www.stench.com"
xmlns:irrelevant="http://sweetaroma.org"
xmlns="dongfang.dk"
odor="a"
irrelevant:odor="b">

<!-- And I would think that these two elements are semantically
indistinguishable
- - although one is 'lexically' a bit more explicit about the namespace
of its
non-"irrelevant"-NS odor attribute than the other .. right? -->

<smelly:inner odor="1" irrelevant:odor="2"/>
<smelly:inner smelly:odor="1" irrelevant:odor="2"/>

<!-- this would be two attributes w same name in same name space and w
same owner element .. an error, right? -->
<smelly:inner smelly:odor="1" odor="2"/>
</smelly:skunk>

TNX for any reply

Soren (who actually needs to decorate element with attributes in a
different NS, without risk o' clashes)
Jul 20 '05 #1
9 1805
What particularly puzzles (annoys) me is that dom4j, in this program:

import java.util.Iterator;
import java.util.List;

import org.dom4j.Attribute;
import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

/**
* @author dongfang
*/
public class AnnoyingDom4jAttributes {
public static void main (String[] args) throws Exception {
String filename =
"experimental-data/AnnoyingAttributes.xml";///args[0];
SAXReader builder = new SAXReader();

//builder.setFeature("http://xml.org/sax/features/namespaces",
true);

//builder.setFeature("http://xml.org/sax/features/namespace-prefixes",
false);

Document doc = builder.read(filename);

Element root = doc.getRootElement();

verbose(root);

for (Iterator children = root.elementIterator();
children.hasNext();) {
verbose((Element)children.next());
}
}

private static void verbose(Element e) {
System.out.println("Naive name: " + e.getName());
System.out.println("qual name: " + e.getQualifiedName());
System.out.println("namespace: " + e.getNamespace());
List attrs = e.attributes();
for (int i=0; i<attrs.size(); i++) {
System.out.println("Att #" + i + ":");
Attribute a = (Attribute)attrs.get(i);
System.out.println(" Naive name: " + a.getName());
System.out.println(" qual name: " + a.getQualifiedName());
System.out.println(" namespace: " + a.getNamespace());
System.out.println(" value: " + a.getValue());
System.out.println("<<owner-element>>.getAttribute("+
a.getName() + ")"+" == this: " + (e.attribute(a.getName())==a));
System.out.println("<<owner-element>>.getAttribute("+
a.getQName() +")"+" == this: " + (e.attribute(a.getQName())==a));
}
System.out.println();
}
}
says about this element:
<smelly:inner odor="1" irrelevant:odor="2"/>
:
Naive name: inner
qual name: smelly:inner
namespace: org.dom4j.Namespace@3d51bec5 [Namespace: prefix smelly mapped
to URI "http://www.stench.com"]
Att #0:
Naive name: odor
qual name: odor
namespace: org.dom4j.Namespace@babe [Namespace: prefix mapped to URI ""]
......

-- the odor attribute is not mapped to the name space of the owner
element, not to the default namespace (dongfang.dk) either, but to the
empty string NS. ARGH.

This one
<smelly:inner smelly:odor="1" irrelevant:odor="2"/>


Naive name: inner
qual name: smelly:inner
namespace: org.dom4j.Namespace@3d51bec5 [Namespace: prefix smelly mapped
to URI "http://www.stench.com"]
Att #0:
Naive name: odor
qual name: smelly:odor
namespace: org.dom4j.Namespace@3d51bec5 [Namespace: prefix smelly
mapped to URI "http://www.stench.com"]

maps the way I like it.

I just wonder, is that a bug I have spotted there, or am I the bug?

JDOM does the same.

Soren
Jul 20 '05 #2
In article <cv**********@news.net.uni-c.dk>,
Soren Kuula <do*******************@bitplanet.net> wrote:

% I just can't find namespaces of attributes stated clearly enough in the
% XML namespace spec.
% But .. I hear rumors that attributes, unless qualified otherwise,
% default to the namespace of the owner element.
% Is that right ?

No. Unqualified attributes have no namespace. What the spec says is that
the default name space does not apply to attributes.

--

Patrick TJ McPhee
North York Canada
pt**@interlog.com
Jul 20 '05 #3


Soren Kuula wrote:

says about this element:
<smelly:inner odor="1" irrelevant:odor="2"/>

:
Naive name: inner
qual name: smelly:inner
namespace: org.dom4j.Namespace@3d51bec5 [Namespace: prefix smelly mapped
to URI "http://www.stench.com"]
Att #0:
Naive name: odor
qual name: odor
namespace: org.dom4j.Namespace@babe [Namespace: prefix mapped to URI ""]
.....

-- the odor attribute is not mapped to the name space of the owner
element, not to the default namespace (dongfang.dk) either, but to the
empty string NS. ARGH.


I don't know JDOM or dom4j in detail but an attribute with a name
without a prefix is indeed in no namespace, check the specification
about namespaces in XML.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 20 '05 #4
Patrick TJ McPhee wrote:
In article <cv**********@news.net.uni-c.dk>,
Soren Kuula <do*******************@bitplanet.net> wrote:

% I just can't find namespaces of attributes stated clearly enough in the
% XML namespace spec.
% But .. I hear rumors that attributes, unless qualified otherwise,
% default to the namespace of the owner element.
% Is that right ?

No. Unqualified attributes have no namespace. What the spec says is that
the default name space does not apply to attributes.

Hi, thank you both of you.

ARGH!
That means, I guess, that most application writers (particularly XSL)
just assume that unqualified attributes are theirs? I have not heard
about many XML authors who bothered to qualify their attributes.

What's the right thing to expect then? I'm writing stuff that processes
XSL stylesheets, it should work with all the ones that have worked in
XSL processors. Right now, I assume that an attribut is XSL if it is in
the XSL namespace, or in the emptd named namespace.

Talking of XSL: Is there a schema for that somewhere? I have seen the
quasi-DTD in the spec -- is there anything around more precise than that?

Finally, can anyone see a good reason for the XML namespace attribute
namespacing design (no qual-->empty namespace) -- why not no
qual-->owner element's namespace? It would be nicer -- in my opinion.

Soren

Jul 20 '05 #5
Soren Kuula <dongfang-remove_this@remove_this-bitplanet.net> writes:
Patrick TJ McPhee wrote:
In article <cv**********@news.net.uni-c.dk>,
Soren Kuula <do*******************@bitplanet.net> wrote:

% I just can't find namespaces of attributes stated clearly enough in the
% XML namespace spec.
% But .. I hear rumors that attributes, unless qualified otherwise,
% default to the namespace of the owner element.
% Is that right ?

No. Unqualified attributes have no namespace. What the spec says is that
the default name space does not apply to attributes.
Hi, thank you both of you.

ARGH!
That means, I guess, that most application writers (particularly XSL)
just assume that unqualified attributes are theirs?


In the case of xsl it's fully specified, so their is no need to assume
anything:
if the element is in the xsl namespace then any unnamespaced attributes
must be as specified in the xslt spec, any other unnamespaced attribute
is a syntax attribute. Any attribute in anamespace (other than xslt
namespace) is allowed in xslt and ignored by defaulut, but may be used
by an extension or documentation system.

conversely if the element is not in the xsl namespace then the xsl spec
says nothing about any attributes (if the element is a literal result
element such attributes are just copied to the result) but elements in
the xsl namespace are interpreted by the xsl processor and not copied to
the result.
so for example you put version="..." on xsl:stylesheet
but xsl:version on a top levelelement that is not in the xsl namespace
similarly you use exclude-result-prefixes on an xsl element but
xsl:exclude-result-prefixes on a non-xsl element.
I have not heard
about many XML authors who bothered to qualify their attributes.
mainly used by attributes that have the same meaning whatever namespace
of the element they are used for.
xml:base xsl:version xlink:href etc
What's the right thing to expect then? I'm writing stuff that processes
XSL stylesheets, it should work with all the ones that have worked in
XSL processors. Right now, I assume that an attribut is XSL if it is in
the XSL namespace, or in the emptd named namespace.
see above.
Talking of XSL: Is there a schema for that somewhere? I have seen the
quasi-DTD in the spec -- is there anything around more precise than that?
There's one for XSLT2 likned from the draft.
Finally, can anyone see a good reason for the XML namespace attribute
namespacing design (no qual-->empty namespace) -- why not no
qual-->owner element's namespace? It would be nicer -- in my opinion.
That rule would probably lead to more complicated rules making sure that
<a:x a:y="xx" and y="zz"/>
was (or wasn't) well defined. Presumably with your suggested rule this
would be an error as both attributes would be y in the namespace
associated with a:? It doesn't seem any more useful than the current
rule, really. Any rule is fairly arbitary.

Soren


David
Jul 20 '05 #6
In article <KW*********************@news000.worldonline.dk> ,
Soren Kuula <dongfang-remove_this@remove_this-bitplanet.net> wrote:
That means, I guess, that most application writers (particularly XSL)
just assume that unqualified attributes are theirs? I have not heard
about many XML authors who bothered to qualify their attributes.
The way to look at it is that unprefixed attributes "belong to" the
element they're on. The only point to prefixing attributes is to
allow them to be used on elements from other namespaces. That's why
the attributes on XSL or XML Schema elements are unprefixed, while the
attributes defined by those standards that are used on your own
attributes (xsl:version, xsi:type etc) are prefixed.

Since the namespace spec was first drafted, there's been a drift in
terminology from considering things to be "in" namespaces to
considering them just as having qualified names with a namespace and
local part. If you wish, you can consider unprefixed attributes to be
conceptually in the namespace of their element (or as an appendix to
Namespaces 1.0 put it, in one of the "per-element partitions" of that
namespace), but specs and APIs generally talk in terms of qualified
names, and the qualified name of an unprefixed attribute has a null
namespace name.
Finally, can anyone see a good reason for the XML namespace attribute
namespacing design (no qual-->empty namespace) -- why not no
qual-->owner element's namespace? It would be nicer -- in my opinion.


I think one reason is that people didn't want to suggest that there
can only be one foo attribute in a given namespace. The foo
attributes of different elements in the namespace are different
attributes. Hence the "per-element partitions". I think this was a
mistake, and what you suggest would have saved a lot of confusion, but
it's too late now.

-- Richard
Jul 20 '05 #7
Hi, David, thanks for the response,
if the element is in the xsl namespace then any unnamespaced attributes
must be as specified in the xslt spec, any other unnamespaced attribute
is a syntax attribute. Any attribute in anamespace (other than xslt
namespace) is allowed in xslt and ignored by defaulut, but may be used
by an extension or documentation system.
I read it that these are equivalent in XSL, then:
<xsl:template xsl:match="...">...</xsl:template>

<xsl:template match="...">...</xsl:template>

For completeness, I will have to check both versions when looking for
the "match" attribute (and, presumable complain if both are present?).
Oh well, could have been worse :)
That rule would probably lead to more complicated rules making sure that
<a:x a:y="xx" and y="zz"/>
was (or wasn't) well defined. Presumably with your suggested rule this
would be an error as both attributes would be y in the namespace
associated with a:?
Yes

It doesn't seem any more useful than the current rule, really. Any rule is fairly arbitary.


It would have made my check easier :)

BTW, I failed in making a purely imaginary example document.
http://www.stench.com has a target, would you imagine :)

Soren

Jul 20 '05 #8
In article <W_*********************@news000.worldonline.dk> ,
Soren Kuula <dongfang-remove_this@remove_this-bitplanet.net> wrote:
I read it that these are equivalent in XSL, then:
<xsl:template xsl:match="...">...</xsl:template>

<xsl:template match="...">...</xsl:template>


No, the first is not allowed.

-- Richard
Jul 20 '05 #9

I read it that these are equivalent in XSL, then:
<xsl:template xsl:match="...">...</xsl:template>
No, that is a syntax error. There is no xsl:match attribute in xsl.
David
Jul 20 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Francis Avila | last post by:
A little annoyed one day that I couldn't use the statefulness of generators as "resumable functions", I came across Hettinger's PEP 288 (http://www.python.org/peps/pep-0288.html, still listed as...
50
by: Dan Perl | last post by:
There is something with initializing mutable class attributes that I am struggling with. I'll use an example to explain: class Father: attr1=None # this is OK attr2= # this is wrong...
1
by: wooks | last post by:
I have some information embedded in included schemas which I want to access at run-time for the purposes of contructing a GUI (they will support field labels and tool tips). The options seem to...
0
by: Soren Kuula | last post by:
Hi, I just can't find namespaces of attributes states clearly enough in the XML namespace spec. But .. I hear rumors that attributes, unless qualified otherwise, default to the namespace of the...
14
by: Viken Karaguesian | last post by:
Hello all, It stinks being a newbie! One thing that I'm not sure about with CSS is: where is the "proper" place to put font attibutes? This has me a little confused. Take the below style sheet...
4
by: Pedro Werneck | last post by:
Hi all I noticed something strange here while explaining decorators to someone. Not any real use code, but I think it's worth mentioning. When I access a class attribute, on a class with a...
23
by: Frank Millman | last post by:
Hi all I have a small problem. I have come up with a solution, but I don't know if it is a) safe, and b) optimal. I have a class with a number of attributes, but for various reasons I cannot...
26
by: tjhnson | last post by:
Hi, With properties, attributes and methods seem very similar. I was wondering what techniques people use to give clues to end users as to which 'things' are methods and which are attributes. ...
11
by: Rafe | last post by:
Hi, I'm working within an application (making a lot of wrappers), but the application is not case sensitive. For example, Typing obj.name, obj.Name, or even object.naMe is all fine (as far as...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.