TopLink Wiki
Main
RecentChanges
Set your name in
UserPreferences
Referenced by
JSPWiki v2.0.52
|
Introduction to TopLink Object-XML Mapping
Simple example of writing an object to XML. forum:288692
import javax.xml.bind.*;
import javax.xml.parsers.*;
import org.w3c.dom.*;
...
Vector objects = session.readAllObjects;
JAXBContext jaxbContext = JAXBContext.newInstance("your_context_path");
Marshaller marshaller = jaxbContext.createMarshaller();
// Create an XML document to contain the fragments
DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = builderFactory.newDocumentBuilder();
Document document = builder.newDocument();
Element root = document.createElement("root");
document.appendChild(rootElement);
// Marshal each of the objects to the owning document
for (Iterator i = objects.iterator(); i.hasNext(); ) {
marshaller.marshal(i.next(), root);
}
|
||||||