*
The moose likes XML and Related Technologies and the fly likes XML beginner Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "XML beginner" Watch "XML beginner" New topic
Author

XML beginner

David Spades
Ranch Hand

Joined: Feb 01, 2014
Posts: 194


Why do <user> elements must also be prefixed? isn't the prefix on applicationUsers supposed to automatically make all child elements to be associated to abc?
the second question is, is it possible for a single element to be associated to multiple namespace?
thanks
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

David Spades wrote:isn't the prefix on applicationUsers supposed to automatically make all child elements to be associated to abc?


No. The default namespace is inherited by child elements, but prefixed namespaces aren't.

the second question is, is it possible for a single element to be associated to multiple namespace?


No.
David Spades
Ranch Hand

Joined: Feb 01, 2014
Posts: 194
so, basically this:


is no different from



from software's point of view?

Also, I have seen that it's possible for an element to have one namespace while its attributes to have other namespace. How does that work?
Thank you.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Yes, that's right. In the first example you have a namespace declaration which doesn't apply to any nodes in the document. Since it's unused, yes, it can be removed. However...



and



are NOT the same, because in the first version all of the elements (but not the attributes) are in the default namespace, and in the second version all of the nodes are in no namespace.

David Spades wrote:Also, I have seen that it's possible for an element to have one namespace while its attributes to have other namespace. How does that work?


An element and its attributes are different nodes. And therefore they can be in different namespaces (and they often are).
g tsuji
Ranch Hand

Joined: Jan 18, 2011
Posts: 499
    
    3
David Spades wrote:Why do <user> elements must also be prefixed? isn't the prefix on applicationUsers supposed to automatically make all child elements to be associated to abc?

Namespace declaration is one thing; element name (prefixed or not and in the latter case with or without default namespace declaration) is another. You should rather reason along like this: namespace declaration of an element makes the declaration "in-scope" for all its descendant elements until countered by another declaration changing its status. It being in-scope does not make it automatic such that the descendants live in that namespace - and the namespace declaration can be multiple in the root - the top element of that tree, and by this fact itself, it is already clear that reasoning wouldn't hold. Making a descendant be in a namespace is a positive action taken by the author(s) of the document - one by one, and each one counts. It must be explicit.

Default namespace is only a shorthand to spare the author(s) of the document the trouble of making an element's name fully qualified via a prefixed so defined in the declaration. Nothing less and nothing more. It does not carry the meaning of being default of something for its descendants.

The prefix itself has no generic significance, it is the namespace uri that counts.

David Spades wrote:Also, I have seen that it's possible for an element to have one namespace while its attributes to have other namespace. How does that work?

In the majority of cases, you would see an attribute of an element carries no prefix. Even if there were a default namespace in the scope, it does _not_ mean the attribute lives in that default namespace. As a rule, all attributes living in a non null namespace _must_ be prefixed and the prefix declared. There is no such thing as the default namespace for an attribute.

An attribute of name without prefix in principle lives in empty (or null) namespace. It could be "attached" to an element in the sense of its being defined in the schema where the attaching element is being defined.

If an attribute is prefixed, that attribute _must_ be defined in an schema validating that namespace as a top-level element inside the schema. That is how it works in the perspective of xml document with a validating schema.

At the beginning where no conscious is required on how w3c schema works, some of the light on how and why xml document looks like what it looks like might not come out to the light very easily. It therefore requires multi-pass to understand the various facets of it. It is hard to force the thing. It would come naturally.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: XML beginner
 
Similar Threads
Namespace Scope
Query of Oracle to SQL Server
NameSpace Prefix
Name Spaces Questions
Assigning xml namespaces to a prefix