This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Web Services and the fly likes XML validation problem 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 » Java » Web Services
Bookmark "XML validation problem" Watch "XML validation problem" New topic
Author

XML validation problem

Harald Fiedler
Greenhorn

Joined: Jul 31, 2012
Posts: 3
I have some problens with validating my xml file. I get the error message "cvc-elt.1: Cannot find the declaration of element 'xsi:settings'." in my xml file . To me, my code is correct, but obviously it shouldn't be..

My xml file:



My xsd file(has no errors):



If i change the xsi:settings in settings, in the xml, i get a "No grammar constraints (DTD or XML Schema) referenced in the document.".

Thanks in advance for your help.

Just a Game
g tsuji
Ranch Hand

Joined: Jan 18, 2011
Posts: 499
    
    3
[1]
<xsi:settings xmlns:xsi="http://www.w3.org/2001/XMLSchema" xsi:noNamespaceSchemaLocation="http://www.w3.org/2001/XMLSchema/Application.xsd">

should read

[1.1] Related to it the close tag should thereby be </settings>, as a matter of course.

[1.2] I take the assumption that settings is an element in no namespace. That is the assumption up to now the most reasonable to make. If not, it cannot in the well-known namespace of XMLSchema in any case. That is guaranteed to be an error.

[1.3] There is normally no pressing reason even to specify the location of the schema document, unless for some reason related only to the way you have in mind how the xml document is consumed that ought to do so.

[2] Here in your "your_schema.xsd", say:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.w3.org/2001/XMLSchema" >

should read

[2.1] There should not be a targetNamespace attribute there as the document to be described by it is in no namespace.

edit note: rectified the xsi namespace propre.
Harald Fiedler
Greenhorn

Joined: Jul 31, 2012
Posts: 3
Thank you very much for these explanations. It works. However, i tried to change the name of my namespaces and it didn't work. I got an error for each element which told me that "http://www.w3.org/2001/XMLSchema" is the apropriate name.
g tsuji
Ranch Hand

Joined: Jan 18, 2011
Posts: 499
    
    3
However, i tried to change the name of my namespaces and it didn't work.

This is an exercise that practically rarely help by trial-and-error, you risk even to pick up wrong concepts. There are many elements that must be working together in the schema design to validate certain type of document instances. You've to look at many correct realizations to realize all elements you read and learned on w3c schema suddenly falling into place.

[3] If you want to make the vocabulary used in your xml document defined in a namespace---your own, you _can't_ borrow some well-known namespace such as http://www.w3.org/2001/XMLSchema, for instance---with its urn being say "urn:xyz" for instance. This is how it would look like. (Namespace prefix is arbitrary but governed by the syntactic requirement all the same. But I use the device of default namespace to make you confuse for a moment, I hope not for long. You have to read tutorials, and at some later time, the recommendation itself after you've got some ideas of the key concepts.)

[4] And then your_schema.xsd would eventually look like this.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: XML validation problem
 
Similar Threads
Problem in XSD
Help me for xsd creation
Creating a JMS TextMessage From XML
<xsd:attribute> & <xsd:sequence> mutually exclusive???