Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a good library for generating arbitrary XML from Java? [closed]

Tags:

java

xml

I need to generate a number of XML documents from Java objects. The objects are deep ORM mapped objects, and the XML documents are for a search index (a la Lucene). I want to be able to create a configuration file and feed it a Java object and have it spit out the XML specified in the configuration. Ideally the configuration would consist of a mapping of (possibly deep) properties on the java side to XPath or something very much like it on the XML side.

JAXB is unsuitable because it wants to the create a one to one mapping from object data to XML nodes. I've looked at JIBX and XStream but neither of them seem to be designed to do what I'm talking about.

Essentially what I want is Dozer, but designed to create an XML document as its target rather than another Java bean. From my research so far it looks like I'm going to have to write this myself. Can anyone offer a better alternative?

EDIT: The solution must not be predicated on the ability to modify the source Java files. Annotation based systems are comepletely useless to my purposes here. It should be possible to define 'translators' for the individual mappings just as it is in Dozer.

It should be noted that I need to be able to specify that a given input field in java might be output in several different places in the XML output, perhaps being transformed in some cases and not in others.

I've already considered doing some sort of straight Java to XML translation of the objects and then performing my task using XSLT, but the problem with that is that these are deep objects with bidirectional connections. Any mapping of the objects to XML would have a difficult time figuring out how deep in object hierarchy to go, even if it could keep track of which objects should be discounted because they'd been seen already.

like image 897
Jherico Avatar asked Jan 11 '10 20:01

Jherico


People also ask

Which is an open source Java based library to parse XML document?

A - JDOM is an open source, java based library to parse XML document.

What is XML used for in Java?

XML provides a universal syntax for Java semantics (behavior). Simply put, this means that a developer can create descriptions for different types of data to make the data behave in various ways with Java programming code, and can later repeatedly use and modify those descriptions.

Does Java support XML?

Using the XML Parser for Java: Basic ProcessThe DOM or SAX parser parses input XML documents. For example, the program can parse XML data documents, DTDs, XML schemas, and XSL stylesheets.


1 Answers

i use this: Simple

like image 192
pstanton Avatar answered Sep 30 '22 19:09

pstanton