Jump to: navigation, search

Difference between revisions of "EclipseLink/Examples/MOXy/Dynamic/DynamicEntityToXml"

< EclipseLink‎ | Examples‎ | MOXy‎ | Dynamic
(New page: ==Overview== In this example we will show how to create dynamic entities and marshal then to XML. ==Create Dynamic Entities== <source lang="java"> DynamicEntity customer = jaxbContext.new...)
 
(Create Dynamic Entities)
Line 4: Line 4:
 
==Create Dynamic Entities==
 
==Create Dynamic Entities==
 
<source lang="java">
 
<source lang="java">
DynamicEntity customer = jaxbContext.newDynamicEntity("org.example.customer.Customer");
+
DynamicEntity customer = jaxbContext.newDynamicEntity("org.example.Customer");
 
customer.set("name", "Jane Doe");
 
customer.set("name", "Jane Doe");
  
DynamicEntity address = jaxbContext.newDynamicEntity("org.example.customer.Address");
+
DynamicEntity address = jaxbContext.newDynamicEntity("org.example.Address");
 
address.set("street", "1 Any Street");
 
address.set("street", "1 Any Street");
 
address.set("city", "Any Town");
 
address.set("city", "Any Town");

Revision as of 11:57, 24 June 2010

Overview

In this example we will show how to create dynamic entities and marshal then to XML.

Create Dynamic Entities

DynamicEntity customer = jaxbContext.newDynamicEntity("org.example.Customer");
customer.set("name", "Jane Doe");
 
DynamicEntity address = jaxbContext.newDynamicEntity("org.example.Address");
address.set("street", "1 Any Street");
address.set("city", "Any Town");
customer.set("address", address);

Marshal Dynamic Entities to XML

Marshaller marshaller = jaxbContext.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.marshal(customer, System.out);