Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Marshalling attributes as node, why ?
Marshalling attributes as node, why ? [message #521808] Thu, 18 March 2010 18:48 Go to next message
kladrian  is currently offline kladrian Friend
Messages: 2
Registered: March 2010
Junior Member
I'm using eclipse link (OSGI version) to read/write an XML file; something like this:

<root>
   <node attribute0="some value" attribute1="some other value" />
</root>


when I create a marshaller and write the xml file I got its content modified and no longer fit its XSD scheme.
Opening the just created xml file i find attributes as nodes, like this:

<root>
   <node>
       <attribute0>some value</attribute0>
       <attribute1>some other value</attribute1>
   </node>
</root>


this is the code I use to write xml file:

File myXMLFile = new File("/home/myName/myfile.xml");
Root rootNode = myObjectFactory.createRoot();
//...some other lines
//...some try and catch
Marshaller marshaller = jaxbContext.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
marshaller.marshal(root, myXMLFile);


The linked class "Node" has properties "attribute0" and "attribute1" as @XmlAttribute

any one can help me ?
many thanks Smile
Re: Marshalling attributes as node, why ? [message #521837 is a reply to message #521808] Thu, 18 March 2010 21:10 Go to previous messageGo to next message
Blaise Doughan is currently offline Blaise DoughanFriend
Messages: 163
Registered: July 2009
Senior Member

If you have the following the you should see properties attribute0 & attribute1 marshal as attributes. Can you share your model?

import javax.xml.bind.annotation.XmlAttribute;

public class Node {

    private String attribute0;
    private String attribute1;

    @XmlAttribute
    public String getAttribute0() {
        return attribute0;
    }

    public void setAttribute0(String attribute0) {
        this.attribute0 = attribute0;
    }

    @XmlAttribute
    public String getAttribute1() {
        return attribute1;
    }

    public void setAttribute1(String attribute1) {
        this.attribute1 = attribute1;
    }

}


-Blaise
Re: Marshalling attributes as node, why ? [message #521912 is a reply to message #521808] Fri, 19 March 2010 09:34 Go to previous messageGo to next message
Nicola is currently offline NicolaFriend
Messages: 4
Registered: July 2009
Junior Member
Hi, I have the same issue, I'm using EclipseLink OSGI version 2.0.1.
I have tested with the model you proposed and a blank project, this is the Activator class:
	public void start(BundleContext context) throws Exception
	{
		JAXBContext jaxbContext = null;
		jaxbContext = JAXBContext.newInstance("my.models", new BundleProxyClassLoader(context.getBundle()));

		Node n = new Node();
		n.setAttribute0("mioatt0");
		n.setAttribute1("mioatt1");
 
        // Step 2 - Convert the Domain Model to XML
 
        Marshaller marshaller = jaxbContext.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
 
        marshaller.marshal(new ObjectFactory().createNode(n), System.out);
	}

I have found BundleProxyClassLoader somewhere in another user thread to let MOXy find ObjectFactory inside my models package.

This is the output of ss:
Framework is launched.

id	State       Bundle
0	ACTIVE      org.eclipse.osgi_3.5.1.R35x_v20090827
	            Fragments=9
1	ACTIVE      org.eclipse.persistence.core_2.0.1.v20100213-r6600
	            Fragments=2
2	RESOLVED    org.eclipse.persistence.oracle_2.0.1.v20100213-r6600
	            Master=1
3	ACTIVE      javax.xml_1.3.4.v200902170245
4	ACTIVE      javax.activation_1.1.0.v200906290531
5	ACTIVE      org.eclipse.persistence.moxy_2.0.1.v20100213-r6600
6	ACTIVE      javax.persistence_2.0.0.v201002051058
7	ACTIVE      javax.mail_1.4.0.v200905040518
8	ACTIVE      provaxml_1.0.0.qualifier
9	RESOLVED    org.eclipse.persistence.jpa.equinox.weaving_2.0.1.v20100213-r6600
	            Master=0
10	ACTIVE      javax.resource_1.5.0.v200906010428
11	ACTIVE      org.eclipse.persistence.asm_2.0.1.v20100213-r6600
12	ACTIVE      javax.xml.stream_1.0.1.v201001131653
13	ACTIVE      javax.jms_1.1.0.v200906010428
14	ACTIVE      javax.transaction_1.1.0.v201002051055
15	ACTIVE      org.eclipse.persistence.antlr_2.0.1.v20100213-r6600
16	ACTIVE      javax.xml.bind_2.1.12.v200912160909

bundle 8 is my testbundle.

and this is the output:
osgi> <START>
org.eclipse.persistence.jaxb.JAXBContext
<?xml version="1.0" encoding="UTF-8"?>
<ns0:node xsi:type="node" xmlns:ns0="http://my.models" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <attribute0>mioatt0</attribute0>
   <attribute1>mioatt1</attribute1>
</ns0:node>
<END>


If I use non OSGI version of EclipseLink MOXy the XML output is OK :-\

[Updated on: Fri, 19 March 2010 09:35]

Report message to a moderator

Re: Marshalling attributes as node, why ? [message #521963 is a reply to message #521808] Fri, 19 March 2010 13:31 Go to previous message
Nicola is currently offline NicolaFriend
Messages: 4
Registered: July 2009
Junior Member
Uhmm, seems like I have solved my issue ...
I added javax.xml.bind.annotation in manifest.mf, Import-Package section, it appears strange to me since I didn't get class not found error or others problems inspecting the package and its imported packages from osgi console commands.

Confused

Smile well hope this help

[Updated on: Fri, 19 March 2010 13:31]

Report message to a moderator

Previous Topic:External file to specify DB information
Next Topic:Error Logging in to the database
Goto Forum:
  


Current Time: Thu Apr 18 13:54:26 GMT 2024

Powered by FUDForum. Page generated in 0.02078 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top