Here's Krzysztof's original question:
Just for completeness, what schema would make the following xml valid:
<tns:foo xmlns:tns="http://www.foo.com"> <tns:bar>cory</tns:bar> <tns:baz>anne</tns:baz> </tns:foo>
To clarify: how do you make bar and baz part of the http://www.bar.com namespace?
First some definitions:
Global element = an element definition that is a direct child of the <schema> element.
Local element = an element definition that is not a direct child of the <schema> element (e.g., it is a child/descendant of a <complexType> definition)
The elementFormDefault and attributeFormDefault attributes are specified on the <schema> element to indicate what the default behavior should be in regards to whether local element and attribute definitions should be included in the targetNamespace. elementFormDefault="unqualified" is the default value, and it indicates that local elements should not be included in the targetNamespace.
elementFormDefault="qualified" puts all local elements into the targetNamespace.
You can override the default behavior on an element-by-element basis using the form attribute.
So...
If you do not specify elementFormDefault="qualified", (in other words -- if you take the default value), then only global elements are part of the targetNamespace. In this situation, you would have to define bar and baz as global elements to make them part of the namespace. Such as something like this:
<schema targetName="http://www.foo.com" xmlns:tns="http://www.foo.com"/> <element name="foo"> <complexType> <sequence> <element ref="tns:bar" /> <element ref="tns:baz" /> </sequence> <complexType> </element> <element name="bar" type="xsd:string"/> <element name="baz" type="xsd:string"/> </schema>
Alternatively, you can specify that all local elements should be part of the targetNamespace by specifying elementFormDefault="qualified". Such as:
<schema targetName="http://www.foo.com" elementFormDefault="qualified"/> <element name="foo"> <complexType> <sequence> <element name=bar" type="xsd:string"/> <element name="baz" type="xsd:string" /> </sequence> </complexType> </element> </schema>
Or you can leave the default form as "unqualified" and override the default on each element. Such as:
<schema targetName="http://www.foo.com"/> <element name="foo"> <complexType> <sequence> <element name=bar" type="xsd:string" form="qualified"/> <element name="baz" type="xsd:string" form="qualified"/> </sequence> </complexType> </element> </schema>
(Don't you just love XML Schema?!?!)
Anne
At 10:26 AM 9/2/2003 -0700, you wrote:
No, bar and baz need not be global elements (direct children of schema) in order to be in the target namespace of the schema, if their 'form' infoset property is "qualified". This can be done overall for the schema, using elementFormDefault="qualified" or on individual element declarations.
The root element of the document, foo, can only be in the target namespace if it is global.
Jeff
----- Original Message ----- From: "Anne Thomas Manes" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Tuesday, September 02, 2003 9:50 AM Subject: RE: xmlns=" " in the doc\literal SOAP message
> There are a number of ways to do it, but essentially, you have to define > each element as a direct child of the <schema> element. Here's one example: > > <schema targetName="http://www.foo.com" > xmlns:tns="http://www.foo.com"/> > <element name="foo"> > <complexType> > <sequence> > <element ref="tns:bar" /> > <element ref="tns:baz" /> > </sequence> > <complexType> > </element> > <element name="bar" type="xsd:string"/> > <element name="baz" type="xsd:string"/> > </schema> >