ws-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Apache Wiki <>
Subject [Ws Wiki] Update of "FrontPage/Axis/OnlyTopLevelElementHasNamespace" by ChrisEbert
Date Thu, 03 Nov 2005 23:32:37 GMT
Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Ws Wiki" for change notification.

The following page has been changed by ChrisEbert:

New page:
== 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

A valid instance of this schema might look like this:
<tns:foobar xmlns:foobar="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:

== 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 the namespace you think they're in.

View raw message