users@jaxb.java.net

RE: Re: Re: marshalling

From: Lulseged Zerfu <lulseged.zerfu_at_ericsson.com>
Date: Fri, 26 Jun 2009 07:31:42 +0200

Hi

Using what you have suggested removes everything <?xml version="1.0"
encoding="UTF-8" standalone="yes"?>. What I wanted to remove was only
part of it <?xml version="1.0" encoding="UTF-8"?>. That's is remove
standalone="yes".

 marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);


I have solved the second one by using a namespaceprefix.

marshaller.setProperty("com.sun.xml.bind.namespacePrefixMapper", new
CustomNameSpacePrefixMapper());

The CustomNameSpacePrefixMapper extends
com.sun.xml.bind.marshaller.NamespacePrefixMapper and implements one
special method where you can specify which namespace to include:
.
.
.
.
.

public String[] getPreDeclaredNamespaceUris()
{
        return new String[]
        {
                "urn:ietf:params:xml:ns:common-policy",
"urn:ietf:params:xml:ns:pres-rules"
        };
}
.
.
.
.
.



Lulseged
-----Original Message-----
From: Wolfgang Laun [mailto:wolfgang.laun_at_gmail.com]
Sent: den 25 juni 2009 17:54
To: users_at_jaxb.dev.java.net
Subject: Re: Re: marshalling

On 6/25/09, Lulseged Zerfu <lulseged.zerfu_at_ericsson.com> wrote:
> Thanks.
>
> Do you mean that there is a requernment but it can not be done or
> there is no time to fix it?
>

There was a requirement not to generate (useless) xmlns:x="..." where x
was never used in the XML, which is (sort of) the opposite of your
request. Your schema announces subelements of xs:anyType, where you
insert an element from the pr namespace. To automatically handle both
cases, the finished Element tree would have to be inspected by the XML
Writer, determining the xmlns that are actually there, which isn't
always possible anyway.

I think that, if you are at liberty to modify your xsd files, it might
be possible to trick JAXB into believing that a pr element will be in
the XML so that the pr namespace is defined in the <ruleset>.

-W



> Lulseged
>
> -----Original Message-----
> From: Wolfgang Laun [mailto:wolfgang.laun_at_gmail.com]
> Sent: den 25 juni 2009 16:38
> To: users_at_jaxb.dev.java.net
> Subject: Re: marshalling
>
> On 6/25/09, Lulseged Zerfu <lulseged.zerfu_at_ericsson.com> wrote:
>> Hi
>>
>> When marshalling an xml document I get the following xml document:
>> <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
>
> [snip]
>>
>> 1. How can I get ride of standalone="yes"?
>
> marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
>
> Write the <?xml...> as you want to the writer of your XML.
>
> marshaller.marshal(...)
>
> -W
>
>
>> 2. How can I put the name space declaration
>> xmlns:pr="urn:ietf:params:xml:ns:pres-rules" on top like the
>> xmlns:cr="urn:ietf:params:xml:ns:common-policy declaration is?
>>
>
> I think that this has been asked before, but it seems it can't be
done.
>
> -W
>
>
>> Thanks as always.
>>
>> Lulseged
>>
>>
>
> ---------------------------------------------------------------------
> 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