• 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

Problem with XML validation

 
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,
For the below two files:

namespace.xml:


namespace.xsd:


The error i am getting is:

cvc-complex-type.2.4.a: Invalid content was found starting with element 'B'. One of '{"":B}' is expected.


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?

Any guidance will be highly helpful.
Thanks ...
 
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the error message? Have you tried to validate the A document outside of Eclipse?
 
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 Jimmy,
I have edited my code in my previous codes.Please have a look at them and now i have also mentioned the error occuring.

Any guidance will be helpul.

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
<restriction base="string">
<pattern value="\d{3}-\d{3}"/>
</restriction>

What is the purpose of these elements?
 
Marshal
Posts: 28193
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
I don't know enough about Schema to say anything useful about that part of your question. But on the other hand I think there's something you don't understand about namespaces, and using Schema terminology to describe what you are trying to do doesn't help.

So suppose you used a namespace prefix for your namespace. Then which of these two documents do you think would be equivalent to what you originally posted?



 
Ranch Hand
Posts: 734
7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org/namespace" xmlns:tns="http://www.example.org/namespace" elementFormDefault="unqualified">


Your problem encountered is due to elementFormDefault being the default "unqualified". It means that any local element would not be living in the target namespace, instead, if not referenced to some specific imported schema, would be in null namespace. Hence, the error message:

One of '{"":B}' is expected.


This is understandably not the easiest part of w3 schema language to digest.

The line should be written like (which conforms to your intention) - watch the only difference in elementFormDefault.

 
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 tsuji for the reply,
It almost solved my problem,but I still want to ask one more thing:-
Giving elementFormDefualt="unqualified" means that the local elements I declare in my schema wil not be added to my target namespace?
Am I correct or I am getting concepts wrong?

Please guide me through.
Thanks.
 
g tsuji
Ranch Hand
Posts: 734
7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Giving elementFormDefualt="unqualified" means that the local elements I declare in my schema wil not be added to my target namespace?
Am I correct or I am getting concepts wrong?


That's what it means. They will be decoupled from the tns.
 
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 tsuji,
I think I am getting hold of thing now
But,still,if the local elements are decoupled from the target namespace,then how come they are validated in the xml schema if i include the target namespace in the xml instance.How does the validator know in which namespace to find the definition for the local elemnts?I checked and found out that the local unqualifed elements belonged to null namespace,then how come they are verified according to their definition in the xml schema?

Thanks.
 
g tsuji
Ranch Hand
Posts: 734
7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is a normal state that an xml document contains vocabulary drawn from multiple namespace. The same for a schema which actually stands for a collection of schema documents parsed in with specific objectives. Each schema document will be itself "validated" automatically. A vocab, content-model and datatype would be built into the memory. It is true that each xsd taken separately can have at most one target namespace. When either of elementFormDefault or attributeFormDefault is default, unqualified, the content-model and vocab would actually be populated with two kinds of data set, one with the tns and the other corresponds to that of the null ns. With the holistic schema built, there is no reason why it can't assess elements/attributes belonging to null ns. All these rest "verbal" to help the mental process to visualize how things work. Would this help a bit?! The remaining is the 0-&-1-things, I am afraid.
 
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
Reffering to the XML Schema "default" namespace as the "null" namespace might not be concise. The primary purpose of Namespace functionality is to permit the usage of identical element names when creating a document with elements from more than one XML-based language. When you are only using a single vocabulary, a clash of element names cannot occur and declaring a namespace is not really necessary or meaningful.

Aside, unqualified elements will belong to the default namespace. So when an XML Schema document is parsed elements can be qualified or not, it doesn't make a difference as there is only one vocabulary.

When an author is creating a XML Schema, he/she needs to consider if there could be element name clashes in XML instances. Again, this can only happen if there is more than one schema involved in document creation.

It is not normal for XML-based documents to contain elements from more than one language. This is an "exceptional" case and the Namespace functionality was created to permit these type of documents. This is one of the "extensions" built into XML on top of the SGML foundation.
 
g tsuji
Ranch Hand
Posts: 734
7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Reffering to the XML Schema "default" namespace as the "null" namespace might not be concise.


Concise? No, it is straightly wrong. But are you saying I were at certain places in my answers saying so? where?
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic