users@jaxb.java.net

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

From: Tang, Harry <Harry.Tang_at_BellSouth.com>
Date: Thu, 23 Oct 2003 10:46:12 -0400

 Ok, here is my schema and marshalled xml text, just trying to understand
your explaination.

From the schema below you can see that top level element is TRANSACTION,
according to your explaination, it inherits from "targetNamespace", (though
the attribute "TRANNAME" namespace is not clear/shown here???). However the
schema do define next level elements(NAME, RECORD..) namespace via type
definition. I am not sure which one is right for following statement: 1 the
explicitly declaration for these element types make them not inherit from
root element, or 2. elementFormDefault=unqualified makes these element
namespace localized, and resulting in xmlns="" in the marshalled text.
The explaination on this may help me to understand why 1st level elements ,
like NAME, VERSION.., do not inherit namespace from Top level element.
"TRANSACTION". Do other xml parsing tools behave similar like JAXB when
parsing such schema?

Thanks,


Schema:

<schema targetNamespace="http://www.mycom.com/CLIPIF"
xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:clipif="http://www.mycom.com/CLIPIF" elementFormDefault="unqualified"
attributeFormDefault="unqualified">
        <simpleType name="ReqName">
                <restriction base="string">
                        <enumeration value="TIRKS_CKT_ASSGN_SCAN_OPER"/>
                        <enumeration
value="TIRKS_SPECIAL_SVC_CKT_REC_OPER"/>
                </restriction>
        </simpleType>
        <complexType name="RecType">
                <sequence>
                        <element name="CKT_ID" type="string"/>
                </sequence>
                <attribute name="RECNAME" type="string"
fixed="REQUEST_DATA"/>
        </complexType>
        <element name="TRANSACTION">
                <complexType>
                        <sequence>
                                <element name="NAME" type="clipif:ReqName"/>
                                <element name="VERSION"
type="positiveInteger"/>
                                <element name="RECORD"
type="clipif:RecType"/>
                        </sequence>
                        <attribute name="TRANNAME" type="string"
fixed="TRANSACTION"/>
                </complexType>
        </element>
</schema>

Marshalled text:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<TRANSACTION TRANNAME="TRANSACTION" xmlns="http://www.mycom.com/CLIPIF">
    <NAME xmlns="">TIRKS_CKT_ASSGN_SCAN_OPER</NAME>
    <VERSION xmlns="">1</VERSION>
    <RECORD RECNAME="REQUEST_DATA" xmlns="">
        <CKT_ID>S 50/QQQQ/44440000/SC</CKT_ID>
    </RECORD>
</TRANSACTION>



-----Original Message-----
From: Robert Lowe
To: users_at_jaxb.dev.java.net
Sent: 10/22/2003 1:53 PM
Subject: RE: Re: xmlns="" in direct child element.

In an XML document, an element's default namespace is inherited from
it's
parent if not explicitly specified. So, using your earlier example:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<TRANSACTION TRANNAME="TRANSACTION"
xmlns="http://www.myxmlnsdefinition">
    <NAME xmlns="">ASSGN_SCAN_OPER</NAME>
    <VERSION xmlns="">1</VERSION>
    <RECORD RECNAME="REQUEST_DATA" xmlns="">
        <CKT_ID>S 50/QQQQ/44440000/SC</CKT_ID>
        <TKT_ID>
            <TKTTypeId>10</TKTTypeId>
            <TKTTypeValue>tksValue</TKTTypeValue>
        </TKT_ID>
    </RECORD>
</TRANSACTION>

The NAME element needs to explicitly daclare the empty namespace using
xmlns="" because otherwise it would inherit the namespace from the
TRANSACTION element, i.e. xmlns="http://www.myxmlnsdefinition".

On the other hand, the CKT_ID element does *not* need to declare the
namespace using xmlns="" (although it *could*) because it already
inherits
this namespace from the RECORD element.



Best regards,

Robert Lowe
http://RMLowe.com/



-----Original Message-----
From: Tang, Harry [mailto:Harry.Tang_at_bellsouth.com]
Sent: Wednesday, October 22, 2003 9:06 PM
To: 'users_at_jaxb.dev.java.net'
Subject: RE: Re: xmlns="" in direct child element.


Thanks for all the suggestions as alternate to eliminate the "xmlns=""
for
child level element. It is really nice to know the alternate solution.
Now
I have a question arising from this, say if I set elementFormDefault as
"unqualified", why only the second level element has the null name space
for
the type, i.e. xmlns="", why jaxb did not carry it through all its
element
type of the schema as this format xmlns="", just to be consistent?


-----Original Message-----
From: Malachi de Aelfweald [mailto:malachid_at_temporal-wave.com]
Sent: Monday, October 20, 2003 3:48 PM
To: users_at_jaxb.dev.java.net
Subject: RE: Re: xmlns="" in direct child element.


It works quite well from my testing of it. Here's what I am doing to
help speed you along doing it yourself:

package com.temporalwave.spec;

import com.sun.xml.bind.marshaller.NamespacePrefixMapper;
import java.util.*;

public class NSPrefixMapper
extends NamespacePrefixMapper
{
        HashMap mappings;

        public NSPrefixMapper()
        {
                mappings = new HashMap();
                setDefaultMappings();
        }

        protected void setDefaultMappings()
        {
                clear();
                addMapping("http://www.temporal-wave.com/spec/dynarray",
"dyn");
                addMapping("http://www.temporal-wave.com/spec/taskman",
"tm");
                addMapping("http://www.w3.org/2001/XMLSchema-instance",
"xsi");
                addMapping("http://java.sun.com/xml/ns/jaxb", "jaxb");
        }

        public void addMapping(String uri, String
prefix){mappings.put(uri, prefix);}
        public String getMapping(String uri){return
(String)mappings.get(uri);}
        public HashMap getMappings(){return mappings;}
        public void clear(){mappings.clear();}

        public String getPreferredPrefix(String namespaceURI, String
suggestion, boolean requirePrefix)
        {
                String toReturn = getMapping(namespaceURI);
                if(toReturn != null)
                        return toReturn;

                return suggestion;
        }
}


-----Original Message-----
From: Kohsuke Kawaguchi [mailto:Kohsuke.Kawaguchi_at_Sun.COM]
Sent: Monday, October 20, 2003 12:33 PM
To: users_at_jaxb.dev.java.net


You could also use NamespacePrefixMapper to change how the RI assigns
prefixes. See namespace-prefix sample for details.


regards,
--
Kohsuke Kawaguchi
Sun Microsystems                   kohsuke.kawaguchi_at_sun.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
*****
"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.60"
---------------------------------------------------------------------
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
*****
"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.60"
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
For additional commands, e-mail: users-help_at_jaxb.dev.java.net