• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Unqualified elements namespace

 
Ranch Hand
Posts: 238
1
Eclipse IDE Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sudhanshu Mishra
Ranch Hand
Posts: 238
1
Eclipse IDE Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry,will keep it in mind while posting further.
 
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 238
1
Eclipse IDE Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 2187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 238
1
Eclipse IDE Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 2187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Marshal
Posts: 28226
95
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 238
1
Eclipse IDE Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Marshal
Posts: 28226
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic