users@jaxb.java.net

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

From: Robert Lowe <rmlowe_at_rmlowe.com>
Date: Thu, 23 Oct 2003 02:53:27 +0800

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