Hi,
as already said, please have a look at the documentation of the location
attribute first.
http://www.castor.org/reference/html/XML%20data%20binding.html#xml.mapping.mappingfile.locationattribute
Regards
Werner
On 18.02.2010 16:03, ptyagi108 wrote:
Hi ,
I have tried to write a simple test program which reads the data in XML
format which i am getting from third party and convert into the Object model
defined in our company.I am pasting all the components ... but after
marshalling i am not getting desired result i.e populated
BusinessMsgIdentification with Account Object.With the program and mapping
below i am getting fields which are defined in
BusinessMsgIdentification.java alone populated and account inside
BusinessMsgIdentification.java remains null .
BusinessMsgIdentificationMappings.xml
=====================================
<?xml version="1.0" encoding="UTF-8"?>
<mapping>
<class
name="com.ebw.mas.common.datatypes.BusinessMsgIdentificationImpl"
auto-complete="true">
<description>Default mapping for class
com.common.datatypes.BusinessMsgIdentificationImpl</description>
<map-to xml="BusinessMsgIdentification"/>
<field name="receipientMsgId" type="string" required="false"
direct="false" transient="false">
<bind-xml name="RecipMsgID" node="element" reference="false"/>
</field>
<field name="origMsgID" type="string" required="false"
direct="false" transient="false">
<bind-xml name="OrigMsgID" node="element" reference="false"/>
</field>
</class>
<class name="com.ebw.mas.common.datatypes.Account" auto-complete="true">
<description>Default mapping for class
com.common.datatypes.AccountImpl</description>
<map-to xml="BusinessMsgIdentification"/>
<field name="MID" type="string" required="false" direct="false"
transient="false">
<bind-xml name="MID" node="element" reference="false"/>
</field>
<field name="SID" type="string" required="false" direct="false"
transient="false">
<bind-xml name="SID" node="element" reference="false"/>
</field>
<field name="acctNum" type="string" required="false"
direct="false" transient="false">
<bind-xml name="AcctNum" node="element" reference="false"/>
</field>
<field name="SPProg" type="string" required="false"
direct="false" transient="false">
<bind-xml name="SPProg" node="element" reference="false"/>
</field>
<field name="Style" type="string" required="false"
direct="false" transient="false">
<bind-xml name="Style" node="element" reference="false"/>
</field>
</class>
</mapping>
public class MappingTest {
public static void main(String args[]) {
Mapping mapping = new Mapping();
try {
// 1. Load the mapping information from the file
mapping.loadMapping(
"resource\\BusinessMsgIdentificationMappings.xml" );
// 2. Unmarshal the data
Unmarshaller unmar = new Unmarshaller(mapping);
BusinessMsgIdentification businessMsgIdentification =
(BusinessMsgIdentification)unmar.unmarshal(new InputSource(new
FileReader("resource\\BusinessMsgIdentification.xml")));
} catch (Exception e) {
System.out.println(e);
return;
}
}
}
BusinessMsgIdentification.xml
=============================
<BusinessMsgIdentification>
<SPID>009963</SPID>
<SPProg>a</SPProg>
<IMID>009959</IMID>
<IMStyle>a</IMStyle>
<AcctNum>21245</AcctNum>
<OrigMsgID>a</OrigMsgID>
<RecipMsgID>a</RecipMsgID>
</BusinessMsgIdentification>
Please help me with this.
Regards,
Pramod
ptyagi108 wrote:
We are using castor mappings to convert from xml to Objects , i am having
following problem which i do not know how to proceed.
I have an object model where a class named BusinessMsgIdentification holds
the reference of Account object.But in the XML which i am getting from
other source (web service) is as given below.The problem is that some of
the elements under the TAG BusinessMsgIdentification in XML actually map
to fields in Account Object in the object model.
<BusinessMsgIdentification>
<SID>009733</SPID>
<SPProg>Abcd12345</SPProg>
<MID>009656</IMID>
<Style> </IMStyle>
<AcctNum>0</AcctNum>
<OrigMsgID>21628755</OrigMsgID>
<RecipMsgID>21618752</RecipMsgID>
</BusinessMsgIdentification>
BusinessMsgIdentification.java has following method and fields like,
protected Account mAccount;
protected String mOrigMsgID;
protected String mReceipientMsgId;
public String getOrigMsgID(){
return mOrigMsgID;
}
public void setOrigMsgID(String origMsgID){
mOrigMsgID=origMsgID;
}
public String getReceipientMsgId(){
return mReceipientMsgId;
}
public void setReceipientMsgId(String receipientMsgId){
mReceipientMsgId=receipientMsgId;
}
public Account getAccount(){
return mAccount;
}
public void setAccount(Account account){
mAccount=account;
}
The problem for me is that the elements like SID,MID ,SPProg in xml
etc are defined in Account class in my object model, but in XML they
falls within BusinessMsgIdentification TAG.BusinessMsgIdentification holds
a reference of Account class.
Please help me with this as it is very urgent.
Regards,
Pramod
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email