users@jaxb.java.net

RE: Re: xmlns="" in direct child element.

From: Kevin Jones <kevinj_at_develop.com>
Date: Thu, 23 Oct 2003 18:55:17 +0100

> I ask because I was given a schema that explicitly set
> elementFormDefault="unqualified" and I'm curious as to why
> they would do
> that. Clearly they wanted to emphasis that they weren't
> taking the default,
> they wanted it to be that way.

Often one reason this is set explicitly is that some web services
toolkits get the default wrong.

> Are there other consequences of moving all of the (inner)
> local definitions
> into the same namespaces as the schema? Why wouldn't you
> want to do that?

This is often a matter of taste - I prefer to have local elements in no
namespace simply because this seems to mirror more closely the way
programming languages work. For example if I have

(in pseudo schema)

<schema targetNamespace="my.package">
  <complexType name="User">
    <element name="name" type="xsd:string"/>
  </complex>

  <element name="alice" type="tns:User"/>
</schema>

Then in Java this corresponds to

my.package.User alice = new User;
alice.name="alice"

Whereas if I put everything into the targetNamespace that corresponds
more closely to

my.package.User alice = new User;
alice.my.package.name="alice"

But as I said it comes down to personal choice,

Kevin Jones
Developmentor
www.develop.com

> -----Original Message-----
> From: Philip, Tim [mailto:Tim_Philip_at_intuit.com]
> Sent: 23 October 2003 17:48
> To: 'users_at_jaxb.dev.java.net'
> Subject: RE: Re: xmlns="" in direct child element.
>
>
>
> This was really helpful, Kevin. Thanks.
>
> My confusion was that I thought if I defined the default
> namespace on my
> schema element that it would apply to everything. But
> apparently that is
> only the case if I set elementFormDefault="qualified".
>
>
>
>
> Tim.
>
> > -----Original Message-----
> > From: Kevin Jones [mailto:kevinj_at_develop.com]
> > Sent: Thursday, October 23, 2003 9:00 AM
> > To: users_at_jaxb.dev.java.net
> > Subject: RE: Re: xmlns="" in direct child element.
> >
> >
> > "inheriting" was perhaps the wrong term here. Namespaces are
> > said to be
> > in scope, the default namespace is in scope from where it is first
> > defined to all descendant elements unless a descendant element sets
> > xmlns="", this has the effect of "turning off" the default
> > namespace and
> > putting the element into "no namespace" (modulo namespace prefixes).
> >
> > In a schema you have two types of element definition, global
> > and local.
> > Global elements are those defined as direct children of the schema
> > element, local elements are those defined as children of
> other schema
> > definitions, such as your example
> >
> > <complexType name="RecType">
> > <sequence>
> > <!-- this is a 'local' element definition -->
> > <element name="CKT_ID" type="string"/>
> > </sequence>
> > <attribute name="RECNAME" type="string"> fixed="REQUEST_DATA"/>
> > </complexType>
> >
> > By *default* global elements are in the target namespace of
> > the schema,
> > local elements are in "no namespace". Your schema's target
> > namespace is
> > "http://www.mycom.com/CLIPIF" so all global elements in the
> > schema that
> > are used in an XML instance document will be in this namespace, all
> > local element definitions will be in no namespace.
> >
> > Using 'elementFormDefault' changes this behaviour.
> > elementFormDefault="unqualified" is the default setting for
> schema, if
> > you leave out elementFormDefault or you set
> > elementFormDefault="unqualified" you get the same behaviour.
> > However if
> > you set elementFormDefault="qualified" every element from the schema
> > whether local or global will now be in the targetNamespace.
> >
> > You can also set this value on individual elements within the schema
> > (form="[un]qualified").
> >
> > So in your instance document
> >
> > <!-- global element in targetNamespace -->
> > <TRANSACTION TRANNAME="TRANSACTION"
> > xmlns="http://www.myxmlnsdefinition">
> > <!-- local element in no namespace -->
> > <!-- but targetNamespace still in scope so have to set "no
> > namespace" -->
> > <NAME xmlns="">ASSGN_SCAN_OPER</NAME>
> > <!-- local element in no namespace -->
> > <!-- but targetNamespace still in scope so have to set "no
> > namespace" -->
> > <VERSION xmlns="">1</VERSION>
> > <!-- local element in no namespace -->
> > <!-- but targetNamespace still in scope so have to set "no
> > namespace" -->
> > <RECORD RECNAME="REQUEST_DATA" xmlns="">
> > <!-- local element in no namespace -->
> > <!-- but targetNamespace not in scope so do not have
> > to set "no
> > namespace" -->
> > <CKT_ID>S 50/QQQQ/44440000/SC</CKT_ID>
> > <TKT_ID>
> > <TKTTypeId>10</TKTTypeId>
> > <TKTTypeValue>tksValue</TKTTypeValue>
> > </TKT_ID>
> > </RECORD>
> > </TRANSACTION>
> >
> >
> > Hope that helps,
> >
> > Kevin Jones
> > Developmentor
> > www.develop.com
> >
> >
> >
> >
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
> > For additional commands, e-mail: users-help_at_jaxb.dev.java.net
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
> For additional commands, e-mail: users-help_at_jaxb.dev.java.net
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
For additional commands, e-mail: users-help_at_jaxb.dev.java.net