aspose file tools*
The moose likes XML and Related Technologies and the fly likes Unqualified elements namespace Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Unqualified elements namespace" Watch "Unqualified elements namespace" New topic
Author

Unqualified elements namespace

Sudhanshu Mishra
Ranch Hand

Joined: May 28, 2011
Posts: 217

Hi all,
I have a doubt regarding the namespace of unqualified elements in XML document.
If i have unqualified elements as per XSD,then are they in null namespace in my corresponding XML document,or they implicitally use the parents namespace?If so how is there structure validated if they are decoupled from the targetNamespace?

Thanks...
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10102
    
165

Sudhanshu, please do not use all caps for the subject of a topic. That's considered shouting. Some of your posts including this one have been edited to remove the all caps subject line.

[My Blog] [JavaRanch Journal]
Sudhanshu Mishra
Ranch Hand

Joined: May 28, 2011
Posts: 217

Sorry,will keep it in mind while posting further.
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
First, using Namespaces in XML Schema design is an option, i.e. it is not required to create or use Namespaces. When creating XML documents which contain qualified elements, it is best to qualify their child elements as well. Regardless, child elements always belong to their parent.
Sudhanshu Mishra
Ranch Hand

Joined: May 28, 2011
Posts: 217

Thanks Jimmy for the quick reply,
but still i want to make sure what you are trying to tell me.
You mean to say that no matter if the elements are qualified or not,the child elements will always refer to the namespace of the parent.If so,explain the below code

namespace.xml file:



namespace.xsd file




I am unable to understand that if elementFormDefault="unqualified" means that the local elements will not be qualified and will be assumed to be in parent's namespace,why is the xml file showing error(working in eclipse)?The namespace of the root in xml instance is defaultNamespace,but as per rule,<B> should not be qualified and assumed to belong to <A>'s namespace,which is same as defaultNamespace itself,and same is the targetNamespace of <B> in xsd file,then why is error coming?

Thanks...
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
Have you tried to validate the A document outside of Eclipse? What other things have you tried? Can you successfully validate the A document without using a namespace?
Sudhanshu Mishra
Ranch Hand

Joined: May 28, 2011
Posts: 217

Hi,
yes I tried to validate it online using the site XML Validation.There also same error appear saying "{""}:B" expected instead of B.If I declare null namspace as default namespace,then the error vanishes.If i include xmlns="" in declration of B,then also the error disappears.How come the element B comes under null namespace if it was declared in the target namespace in the XSD document?


Thanks...
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
Interesting. I would have to look at it to find the root cause.

There may be variances between the "rules" of XML Schema Namespace processing and actual software implementations. Aside, for validation it is usually better to use a XML DTD rather than a XML Schema. This helps maintain a clean separation between validation and processing logic. DTD is for validation and programming language is for logic and processing of data. The concept of XML Schema is a nightmare which most likely stemmed from non-programming minds
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

As I said in one of your earlier posts, I think the problem is not that you don't understand Schema, but that you don't understand XML namespaces. Here's your example:



In that example your <A> element is in the "http://www.example.org/namespace" because the declaration says so. But your <B> element is also in that namespace, because the default namespace is inherited by child elements. And the error message you're getting says that the schema expects the <B> element to be in no namespace (not in "the null namespace"). You can, as you found out, achieve that by declaring it to be in no namespace:



Note also that if you didn't use the default namespace, but used a namespace prefix instead, that your problem also goes away:



Since your <A> element is now not in the default namespace, your <B> element doesn't inherit its namespace and so (since it isn't prefixed) it is in no namespace, which is again what you want.
Sudhanshu Mishra
Ranch Hand

Joined: May 28, 2011
Posts: 217

Thanks Paul for excellent reply.
It would be really helpful if you could answer just one more question.If the element B in no namespace,then how come the validator know about the definition of B as given as per the target namespace?How does it validates the content of element B?Also,what exactly is the difference between "null namespace" and "no namespace"?


Thanks....
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

Sudhanshu Mishra wrote:If the element B in no namespace,then how come the validator know about the definition of B as given as per the target namespace?How does it validates the content of element B?


Sorry, I know very little about Schema. However it should be clear that the validator knows what namespace your B element is in; what it does with that information, I don't know.

Also,what exactly is the difference between "null namespace" and "no namespace"?


"No namespace" means the element isn't in any namespace. "Null namespace" is a phrase which doesn't mean anything. So there isn't a "difference" between the two phrases except that only one of them means anything.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Unqualified elements namespace