Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » MOXy - specify element form in external bindings
MOXy - specify element form in external bindings [message #812135] Sat, 03 March 2012 04:11 Go to next message
Eclipse User
Hi,

could anyone please tell me if it is possible to specify element form
using external bindings?

What I'm trying to achieve is mapping for the following example xsd
(showing just a fragment):

<schema targetNamespace="myNS"
elementFormDefault="qualified"
xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:tns="myNS">

<element name="MESSAGE" type="tns:SomeTypeName" />
<complexType name="SomeTypeName">
<sequence>
<element name="HEADER" type="tns:Header" form="unqualified" />
</sequence>
</complexType>

</schema>

I'd like to have an external mapping document that is able to produce
such a representation:

<m:MESSAGE>
<HEADER>
...
</HEADER>
</m:MESSAGE>

Root qualification should be addressed by <xml-ns> element in an
external binding document.

But how do I instruct MOXy that the HEADER element should be unqualified?

Thanks,
Tom
Re: MOXy - specify element form in external bindings [message #814100 is a reply to message #812135] Mon, 05 March 2012 22:01 Go to previous messageGo to next message
Rick Barkhouse is currently offline Rick Barkhouse
Messages: 22
Registered: July 2009
Junior Member
Hi Tom,

There looks to be a bug in our bindings file support with regards to this scenario, we have reproduced it and should have an update soon.

For what it's worth, the equivalent annotations do work:

[package-info.java]
@javax.xml.bind.annotation.XmlSchema(
xmlns = {
@javax.xml.bind.annotation.XmlNs(prefix = "m",
namespaceURI="myNS")
},
namespace = "myNs",
attributeFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED,
elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED)
package example;

[Sample.java]
@XmlRootElement(name="MESSAGE",namespace="myNS")
public class Sample {

@XmlElement(name="HEADER",namespace="")
public String foo = "info";

}



Thanks,

Rick Barkhouse
EclipseLink

[Updated on: Mon, 05 March 2012 22:25]

Report message to a moderator

Re: MOXy - specify element form in external bindings [message #815486 is a reply to message #814100] Wed, 07 March 2012 13:22 Go to previous messageGo to next message
Eclipse User
I'm not sure if you got me right.

My problem is not that the root element does not get prefixed with the
one specified using <xml-ns>. For that I have entered a issue in
bugzilla (Bug 373159).


The thing is that I want an arbitrarily nested element to be specified
to be marshalled as 'local', i.e. not prefixed.

Say I have a schema (test.xsd):
<?xml version="1.0" encoding="UTF-8"?>
<schema elementFormDefault="qualified" attributeFormDefault="unqualified"
xmlns="http://www.w3.org/2001/XMLSchema"
targetNamespace="test"
xmlns:tns="test">

<element name="ROOT" type="tns:TypeOfRoot"/>

<complexType name="TypeOfRoot">
<sequence>
<element name="ELEMENT_ONE" type="string"/>
<element name="ELEMENT_TWO" type="string" form="unqualified"/>
<element name="ELEMENT_THREE" type="string"/>
</sequence>
</complexType>
</schema>

Notice ELEMENT_TWO that has form="unqualified".

And this xml instance (text.xml):
<?xml version="1.0" encoding="UTF-8"?>
<t:ROOT xmlns:t="test"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="test test.xsd">
<t:ELEMENT_ONE>t:ELEMENT_ONE</t:ELEMENT_ONE>
<ELEMENT_TWO>ELEMENT_TWO</ELEMENT_TWO>
<t:ELEMENT_THREE>t:ELEMENT_THREE</t:ELEMENT_THREE>
</t:ROOT>

The xml above is valid. According to the schema ELEMENT_TWO cannot be
prefixed.


How do I specify external bindings so that MOXy produces the XML above
having an example class:

public class Root {
private String elementOne;
private String elementTwo;
private String elementThree;
}


Would this be the correct mapping?

<?xml version="1.0" encoding="UTF-8"?>
<xml-bindings
xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/oxm"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.eclipse.org/eclipselink/xsds/persistence/oxm http://www.eclipse.org/eclipselink/xsds/eclipselink_oxm_2_3.xsd"
version="2.3"
package-name="test">

<xml-schema
attribute-form-default="QUALIFIED"
element-form-default="QUALIFIED"
namespace="test">
<xml-ns namespace-uri="test" prefix="t"/>
</xml-schema>

<java-types>
<java-type name="test.Root">
<xml-root-element name="ROOT"/>
<xml-type prop-order="elementOne elementTwo elementThree"/>

<java-attributes>
<xml-element java-attribute="elementTwo" namespace=""/>
</java-attributes>
</java-type>
</java-types>
</xml-bindings>


Thanks,
Tom
Re: MOXy - specify element form in external bindings [message #815579 is a reply to message #812135] Wed, 07 March 2012 15:48 Go to previous messageGo to next message
Rick Barkhouse is currently offline Rick Barkhouse
Messages: 22
Registered: July 2009
Junior Member
Hi Tom,

Sorry for the confusion, I'm currently investigating 373159.

For this issue, yes, specifying namespace="" should achieve what you want. Was this not working for you? Below is the bindings.xml I used and the marshalled output:

<?xml version="1.0" encoding="UTF-8"?>
<xml-bindings ...>

    <xml-schema attribute-form-default="QUALIFIED"
        element-form-default="QUALIFIED" namespace="test">
        <xml-ns namespace-uri="test" prefix="t" />
    </xml-schema>

    <java-types>
        <java-type name="test.Root">
            <xml-root-element name="ROOT" />
            <xml-type prop-order="elementOne elementTwo elementThree" />
            <java-attributes>
                <xml-element java-attribute="elementOne" name="ELEMENT_ONE" />
                <xml-element java-attribute="elementTwo" name="ELEMENT_TWO" namespace="" />
                <xml-element java-attribute="elementThree" name="ELEMENT_THREE"/>
            </java-attributes>
        </java-type>
    </java-types>
</xml-bindings>


<?xml version="1.0" encoding="UTF-8"?>
<t:ROOT xmlns:t="test">
   <t:ELEMENT_ONE>1</t:ELEMENT_ONE>
   <ELEMENT_TWO>2</ELEMENT_TWO>
   <t:ELEMENT_THREE>3</t:ELEMENT_THREE>
</t:ROOT>

[Updated on: Wed, 07 March 2012 15:54]

Report message to a moderator

Re: MOXy - specify element form in external bindings [message #816322 is a reply to message #815579] Thu, 08 March 2012 12:56 Go to previous message
Eclipse User
Thanks, that actually works. Somehow I couldn't get it to work at the
beginning - I was looking for 'form' option but then found that
specifying namespace='' achieves the expected result.

On 07.03.2012 21:48, Rick Barkhouse wrote:
> is issue, yes, specifying namespace="" should achieve what you want.
> Was this not working for you?
Previous Topic:Dynamic JPA: How to handle auto generated primary key in Dynamic Type?
Next Topic:Problem with persist order in 3 table scenario including inheritance and OneToMany relationship
Goto Forum:
  


Current Time: Wed Jul 30 05:06:59 EDT 2014

Powered by FUDForum. Page generated in 0.03638 seconds