This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes XML and Related Technologies and the fly likes Castor unable to Map - please help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Castor unable to Map - please help" Watch "Castor unable to Map - please help" New topic
Author

Castor unable to Map - please help

Makarandpp Parabpp
Greenhorn

Joined: Nov 21, 2006
Posts: 3
Hi i am using castor to bind java object to xml. I am using mapping file so that i can change the tag name but the tag name don't change.

Java code
try
{
System.out.println(datarecord);
InputStream inputstream = getResourceAsStream("gen_mapping.xml");
System.out.println("InputStream ::::::::: " + inputstream);
Mapping mapping = new Mapping(this.getClass().getClassLoader());
mapping.loadMapping(new InputSource(inputstream));
System.out.println("Mapping ::::::::: " + mapping);

StringWriter writer = new StringWriter();
Marshaller marshal = new Marshaller(writer);
marshal.setMapping(mapping);
Marshaller.marshal(datarecord, writer);
xmlStr = writer.getBuffer().toString();
System.out.println(xmlStr);
//callsessionbean(xmlStr);
}
catch(Exception e)
{
xmlStr = "Inside the exception of Castor Mapping";
System.out.println(xmlStr);
e.printStackTrace();
}

Mapping file
<?xml version="1.0" encoding="UTF-8"?>
<mapping>

<description>Castor generated mapping file</description>
<class name="uk.co.capgemini.www.ChildServiceProvider">
<description>Default mapping for class uk.co.capgemini.www.ChildServiceProvider</description>
<map-to xml="child-service-provider"/>
<field name="name" type="java.lang.String">
<bind-xml name="name" node="element"/>
</field>
<field name="phoneDetails" type="uk.gov.govtalk.www.TelephoneStructure">
<bind-xml name="phone-details" node="element"/>
</field>
</class>
<class name="uk.co.capgemini.www.ChildDemographics">
<description>Default mapping for class uk.co.capgemini.www.ChildDemographics</description>
<map-to xml="child-demographics"/>
<field name="childName" type="uk.co.capgemini.www.IndexPersonName">
<bind-xml name="child-name" node="element"/>
</field>
</class>
<class name="uk.co.capgemini.www.MatchRecord">
<description>Default mapping for class uk.co.capgemini.www.MatchRecord</description>
<map-to xml="match-record"/>
<field name="coreChildDetails" type="uk.co.capgemini.www.ChildDemographics" collection="array">
<bind-xml name="core-child-details" node="element"/>
</field>
<field name="childID" type="uk.co.capgemini.www.ChildId">
<bind-xml name="ChildID" node="element"/>
</field>
<field name="serviceHistory" type="uk.co.capgemini.www.ChildServiceProvision" collection="array">
<bind-xml name="service-history" node="element"/>
</field>
</class>
<class name="uk.gov.govtalk.www.TelephoneStructure">
<description>Default mapping for class uk.gov.govtalk.www.TelephoneStructure</description>
<map-to xml="telephone-structure"/>
<field name="telExtensionNumber" type="java.lang.String">
<bind-xml name="tel-extension-number" node="element"/>
</field>
<field name="telNationalNumber" type="java.lang.String">
<bind-xml name="tel-national-number" node="element"/>
</field>
<field name="telCountryCode" type="java.lang.String">
<bind-xml name="tel-country-code" node="element"/>
</field>
</class>
<class name="uk.co.capgemini.www.ChildServiceProvision">
<description>Default mapping for class uk.co.capgemini.www.ChildServiceProvision</description>
<map-to xml="child-service-provision"/>
<field name="sensitive" type="boolean">
<bind-xml name="sensitive" node="attribute"/>
</field>
<field name="childProvisionID" type="java.lang.Integer">
<bind-xml name="child-provision-iD" node="element"/>
</field>
<field name="type" type="java.lang.String">
<bind-xml name="type" node="element"/>
</field>
<field name="provider" type="uk.co.capgemini.www.ChildServiceProvider">
<bind-xml name="provider" node="element"/>
</field>
</class>
<class name="uk.co.capgemini.www.ChildId">
<description>Default mapping for class uk.co.capgemini.www.ChildId</description>
<map-to xml="ChildID"/>
<field name="Type" type="java.lang.String">
<bind-xml name="Type" node="element"/>
</field>
<field name="Value" type="java.lang.String">
<bind-xml name="Value" node="element"/>
</field>
<field name="Format" type="java.lang.String">
<bind-xml name="Format" node="element"/>
</field>
</class>
<class name="uk.co.capgemini.www.IndexPersonName">
<description>Default mapping for class uk.co.capgemini.www.IndexPersonName</description>
<map-to xml="index-person-name"/>
<field name="familyName" type="java.lang.String">
<bind-xml name="family-name" node="element"/>
</field>
<field name="nameStatus" type="java.lang.Object">
<bind-xml name="name-status" node="element"/>
</field>
<field name="givenName3" type="java.lang.String">
<bind-xml name="given-name3" node="element"/>
</field>
<field name="givenName2" type="java.lang.String">
<bind-xml name="given-name2" node="element"/>
</field>
<field name="givenName1" type="java.lang.String">
<bind-xml name="given-name1" node="element"/>
</field>
<field name="title" type="java.lang.String">
<bind-xml name="title" node="element"/>
</field>
</class>
</mapping>

output string
<?xml version="1.0" encoding="UTF-8"?>
<match-record><core-child-details><child-name><family-name>Kirby</family-name><given-name3>Willy</given-name3><given-name2>Bill</given-name2><given-name1>William</given-name1></child-name></core-child-details><child-iD><type>String</type><value>NHS</value><format>NHS_1</format></child-iD><service-history sensitive="true"><child-provision-iD>1</child-provision-iD><type>Health Check</type><provider><name>NSPCC</name><phone-details><tel-extension-number></tel-extension-number><tel-national-number></tel-national-number><tel-country-code></tel-country-code></phone-details></provider></service-history></match-record>

the child-id remains the same and does not get updated to ChildID.
Please help me out.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Castor unable to Map - please help
 
Similar Threads
Castor - Java highly nested XML problem [Spring]
problem with loading mapping.xml
How to map arraylist containing a list of hashmaps using castor
[Castor] "unmarshalling exception: unable to find FieldDescriptor for"
Problem in castor mapping file