Both files reside in the same folder. I can't validate the file because of:"Cannot find the declaration of element 'cli:set_Id'. I admit that by now I am totally confused about the usage of namespaces. I do know what they are for, but I just cannot get it right.
[ September 25, 2006: Message edited by: Mike Himstead ]
[ September 25, 2006: Message edited by: Mike Himstead ] [ September 25, 2006: Message edited by: Mike Himstead ]
First of all the schema itself is not WELLFORMED(note not the same as valid!!!) as the end tag for schema element is not prefixed with xsd - it should be </xsd:schema>. Hence its not even valid XML.
The problem isnt really namespace related, its just complicated by the fact that you are using them. Based on the instance doc, you seem to want the set_Id selement to be the root, with a child called Id which must be of type "normalizedString" with a restriction that its maxLength must be 16.
You defined a type called cli:TId as a xsd:normalizedString that is restricted to 16 characters, this is perfect. You can now reuse this.
You then defined an element called set_Id which is of type cli:TId. Hence set_Id cannot contain child elements (or attributes) as it is a simple type. That is not what you want as you want set_Id to have a child called cli:Id.
Also, you try to define a 2nd element called Id of type cli:Id. but that wont work as you never defined the type cli:Id.
Here is what you should do 1) Leave the cli:TId alone - this is a valid simpleType derived by restriction.
2) Redfine the cli:set_Id element as follows, to contain the cli:Id element
This defines the root element set_Id to be a complexType with a following sequence of elements as children : Id (only one child in this case). The child Id is defined to be of type cli:TId so its of the restricted type defined earlier. (Note that defining the Id element inside the set_Id element, as opposed to top level like set_Id, means it cannot be a root of the document, which is what you want since set_Id is the required root)
3) Change the targetNamespace to be someURL (no spaces, instance doc does not like space, for reasons you'll see in a second)
This fixes the schema, here it is in full :
4) Instance doc also has a problem. The xsi:schemaLocation attribute takes 2 parameters sepatated by a space. The first is the namespace the schema is in, the second is the schema location. Hence, it should read
Do you now see why whitespaces in the schema namespace name would be a bad idea? It would not be possible to identify where the namespace ended and the schema location started if it were like this
Hence the xmlns:cli="some URI" needs to be changed to xmlns:cli="someURI"
5) In the instance doc, there is no default namespace set, so the Id element must be fully qualified using the namespace defined (the local name is not enough) It should read
This fixes the instance doc, here is is in full :
Hope this helps, im studying for XMLMaster Basic exam at the moment and know that schema/namespace issues can be really confusing.