Hi,
I am having trouble getting castor to do the following. I have two fields in a
java bean, and want to map both fields to one XML element, one being an attribute and the other being content withing the element.
e.g. <
Test att="anAttribute">SomeText</Test>
After searching the net I have not been able to get any other answers or examples on how you would do this.
I put together an example.
I have a java bean, like the following.
public class Test implements Serializable {
private
String attribute;
private String element;
public Test(){}
public String getAttribute() { return attribute; }
public void setAttribute(String attribute) { this.attribute = attribute; }
public String getElement() { return element; }
public void setElement(String element) { this.element = element; }
}
and a mapping file using the following.
<?xml version="1.0"?>
<!DOCTYPE mapping PUBLIC "-//EXOLAB/Castor Mapping DTD Version 1.0//EN"
"http://castor.org/mapping.dtd">
<mapping>
<class name="play.Test">
<map-to xml="Test"/>
<field name="attribute" type="string">
<bind-xml name="Attribute" node="attribute" location="SomeNode"/>
</field>
<field name="element" type="string">
<bind-xml name="SomeNode" node="element" />
</field>
</class>
</mapping>
The XML that I want to generate is like the following. and it seems I can get just about every other permutation other than that.
<?xml version="1.0" encoding="UTF-8"?>
<Test>
<SomeNode Attribute="anAttribute">anElement</SomeNode>
</Test>
With th given mapping file I am getting out the following.
<?xml version="1.0" encoding="UTF-8"?>
<Test>
<SomeNode>anElement</SomeNode>
<SomeNode Attribute="anAttribute"/>
</Test>
I am using castor version 0.9.5.3.
Any help would be appreciated.