users@jaxb.java.net

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

From: Tang, Harry <Harry.Tang_at_BellSouth.com>
Date: Thu, 23 Oct 2003 13:21:55 -0500

 Thanks for clear explaination. Now I understand the jaxb marshalling
behavior on the schema. It would be good to know if other xml parsers
would get same marshalling behavior.e.g. castor. I guess it should,
otherwise it may cause validation problems among distributed systems
while possible different xml parsers are used to marshal/unmarshal xml
based on same schema(if the schema is not well defined as my example
before.).

Thanks,

-----Original Message-----
From: Kevin Jones
To: users_at_jaxb.dev.java.net
Sent: 10/23/2003 11:00 AM
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

*****
"The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential, proprietary, and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from all computers." 117


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