ws-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Apache Wiki <wikidi...@apache.org>
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:
http://wiki.apache.org/ws/FrontPage/Axis/OnlyTopLevelElementHasNamespace

New page:
##language:en
== 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"
   xmlns:s="http://www.w3.org/2001/XMLSchema">
  <s:element name="foobar">
    <s:complexType>
      <s:sequence>
        <s:element name="foo" type="s:string"/>
        <s:element name="bar" type="s:string"/>
      </s:sequence>
    </s:complexType>
  </s:element>
</s:schema>
}}}
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:foobar="some-uri">
  <foo>one</foo>
  <bar>two</bar>
</tns:foobar>
}}}
But another valid instance might look like this:
{{{
<foobar xmlns="some-uri">
  <foo xmlns="">one</foo>
  <bar xmlns="">two</bar>
</foobar>
}}}
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 the namespace you think they're in.

Mime
View raw message