users@jaxb.java.net

Re: default namespace inconsistency?

From: Jason Harrop <jharrop_at_gmail.com>
Date: Fri, 9 May 2008 09:06:18 +1000

What attributes are on the schema's schema element?

On Fri, May 9, 2008 at 8:43 AM, MrKimi <roger_at_senanque.co.nz> wrote:
>
> I use this code:
> -----
> JAXBContext jc = JAXBContext.newInstance(
> "nz.co.telecom.dsm.umts_som" );
> javax.xml.bind.Marshaller m = jc.createMarshaller();
> m.setProperty(javax.xml.bind.Marshaller.JAXB_FORMATTED_OUTPUT,
> Boolean.TRUE);
> m.setProperty(javax.xml.bind.Marshaller.JAXB_ENCODING,"UTF8");
> m.setProperty("com.sun.xml.bind.namespacePrefixMapper",new
> com.sun.xml.bind.marshaller.NamespacePrefixMapper(){
>
> @Override
> public String getPreferredPrefix(String namespaceUri, String
> suggestion, boolean requirePrefix)
> {
> // I want this namespace to be mapped to "xsi"
> if(
> "http://www.w3.org/2001/XMLSchema-instance".equals(namespaceUri) )
> return "xsi";
>
> // I want the namespace foo to be the default namespace.
> if( "http://www.example.com/foo".equals(namespaceUri) )
> return "";
>
> // and the namespace bar will use "b".
> if(
> "http://www.telecom.co.nz/EAI/UMTS_SOM".equals(namespaceUri) )
> return "b";
>
> // otherwise I don't care. Just use the default
> suggestion, whatever it may be.
> return suggestion;
> public String[] getPreDeclaredNamespaceUris() {
> return new String[] {
> "http://www.w3.org/2001/XMLSchema-instance",
> "http://www.telecom.co.nz/EAI/UMTS_SOM" };
> }
>
> });
>
> m.marshal( o, System.out );
> ----
> And I get the following output:
> ------
> <?xml version="1.0" encoding="UTF8" standalone="yes"?>
> <b:createProductOrder xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:b="http://www.telecom.co.nz/EAI/UMTS_SOM">
> <productOrder>
> <customerOrderItems>
> <customerOrderItem>
> <productUpdate>
> ....
> ------
> But I expected I would get
> ------
> <?xml version="1.0" encoding="UTF8" standalone="yes"?>
> <b:createProductOrder xmlns:b="http://www.telecom.co.nz/EAI/UMTS_SOM"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
> <b:productOrder>
> <b:customerOrderItems>
> <b:customerOrderItem>
> <b:productUpdate>
> ...
> ------
> or maybe
> -------
> <?xml version="1.0" encoding="UTF8" standalone="yes"?>
> <createProductOrder xmlns="http://www.telecom.co.nz/EAI/UMTS_SOM"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
> <productOrder>
> <customerOrderItems>
> <customerOrderItem>
> <productUpdate>
> ...
> --------
> Either of which would parse at the destination I send to (and whose code is
> not under my control). What I actually get (the first xml sample above) does
> not parse.
>
> How come I get what I get? I was hoping the NamespacePrefixMapper would help
> but it doesn't make a significant difference, in this case it changes the
> prefix from ns2 to b which shows it is working but not doing what I need.
>
> I generated the classes using xjc from a supplied xsd (again, not under my
> control). xjc was invoked using this (in ant):
>
> <xjc schema="./config/xsd/UMTS_SOMAdapter.xsd"
> destdir="${generated.fulldir}"
> package="nz.co.telecom.dsm.umts_som"/>
>
> Note that I can unmarshall this just fine in JAXB, but the guys I am sending
> it to cannot. They are telling me the XML is not valid because the
> namespaces are neither defaulted nor explicit and I think they have a point.
> What do I do to get xml they can read?
>
> Versions:
> jaxb-impl-2.1.5
> jaxb-api-2.1.5
> jaxb-xjc-2.1.5
>
> --
> View this message in context: http://www.nabble.com/default-namespace-inconsistency--tp17138133p17138133.html
> Sent from the java.net - jaxb users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
> For additional commands, e-mail: users-help_at_jaxb.dev.java.net
>
>