Menu

XML Mapping

Mike Murphy

Axel Mapping

Axel Mapping tools map XML to Beans and Beans to XML. It is non-intrusive and does not require any modifications to the beans. It uses an xml_to_bean configuration file to tell it how to map xml to beans and a bean_to_xml configuration file to tell it how to map beans to xml.

Both the xml_to_bean and bean_to_xml configurations are quite easy to work with and there is a schema for each that provides details on constructing the configurations and help details for each of the elements and attributes. Using tools like eclipse or netbeans you only need to hover over an element or an attribute to get detailed help.

Once you’ve got the configuration done, or near as needs be, and are ready to test you could create a UnitTest in your project and from this call the mapping tool to see the results. You’ll be pleasantly surprised with the ease in which you can make changes and corrections until you’re satisfied with the end results.

A big benefit with this tool is how easy it is to remember what elements map to what beans and also what beans map to what elements. Looking at the mapping file in the future will quickly refresh your memory.

You will also find that the mapping tool is very friendly and gives exact details of any errors that occur during the mapping process making it an easier task to track down a mistake when it happens.

Mapping XML to Beans

How to map an XML file to Java Beans using the xml_to_bean configuration schema.

There are two stages involved in mapping XML to Beans.

  1. Create the XML Mapping File.
    This defines which XML elements map to which beans

The following example shows how easy this is.

<?xml version="1.0" encoding="UTF-8"?>
<xml_to_bean
   xmlns="http://www.xmlactions.org/xml_to_bean"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://www.xmlactions.org/xml_to_bean
                       http://www.xmlactions.org/schema/xml_to_bean.xsd">
    <bean element="first" clas="org.xmlactions.mapping.xml_to_bean.tutorial.First"/>
    <bean element="second" clas="org.xmlactions.mapping.xml_to_bean.tutorial.Second"/>
</xml_to_bean>

Now lets look at the XML for this mapping.

<first id="1" name="first bean">
    <second name="second bean"/>
</first>

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.