Differences between revisions 3 and 4
Revision 3 as of 2005-11-07 20:20:49
Size: 2351
Editor: atlwebproxy2
Comment: Typo fix from ATM on the list. Namespace was mis-named.
Revision 4 as of 2009-09-20 22:48:47
Size: 2351
Editor: localhost
Comment: converted to 1.6 markup
No differences found!

Q. The elements immediately under the top level element in XML serialized by Axis all have an attribute 'xmlns=""'. Why are they there?

From Anne Thomas Manes (posting on the axis-user list):

xmlns="" is the proper way to declare no default namespace, and its the only way to override a previously declared default namespace.

Let me demonstrate with an example. Let's say that you have this schema:

<s:schema targetNamespace="some-uri" elementFormDefault="unqualified"
  <s:element name="foobar">
        <s:element name="foo" type="s:string"/>
        <s:element name="bar" type="s:string"/>

In this schema, "foobar" is in the "some-uri" namespace, but "foo" and "bar" are local elements to "foobar" and they belong to no namespace. Therefore in a valid document instance, these elements must be unqualified.

A valid instance of this schema might look like this:

<tns:foobar xmlns:tns="some-uri">

But another valid instance might look like this:

<foobar xmlns="some-uri">
  <foo xmlns="">one</foo>
  <bar xmlns="">two</bar>

Since "foo" and "bar" are in no namespace, you must override the default namespace in each element.

According to XML Schema, if you don't specify elementFormDefault="qualified", then all local elements default to unqualified -- but .NET has a bug, and it defaults to qualified. Therefore to fix your problem, add elementFormDefault="qualified" to your schema.

Axis sets the default namespace to null because your schema defines the child elements as unqualified. If it didn't set the default namespace to null, then the message would not match the schema.

If you add elementFormDefault="qualified" to your schema element, then the child elements will be defined as qualified.

For the curious, the relevant bit of the 2001 RFC is: http://www.w3.org/TR/2001/REC-xmlschema-1-20010502/#declare-element

Q. Uh, what's the short answer?

Put attribute elementFormDefault="qualified" on your <schema> tag. The sub elements of the elements you declare aren't in any namespace unless you force them to be.

FrontPage/Axis/OnlyTopLevelElementHasNamespace (last edited 2009-09-20 22:48:47 by localhost)