To Castor
Users,
I'm trying to
populate an existing xml document. However, instead of putting the values in the
existing document, castor recreates the tags at the end of the XML document (See
the output to understand the problem clearly). Please provide some assistance if
you have encounter this problem. Your help will be highly appreciated.
Jerson
Java
Code
DocumentBuilderFactory
dfactory =
DocumentBuilderFactory.newInstance();dfactory.setNamespaceAware(true);
Document doc = dfactory.newDocumentBuilder().parse(new InputSource(new FileInputStream("D:/castor-0.9.5.3/POC/T2.0.xml")));
Marshaller marshaller = new Marshaller(doc);
Mapping mapping = new Mapping();
mapping.loadMapping("D:/castor-0.9.5.3/POC/mapping.xml");
marshaller.setMapping(mapping);
marshaller.marshal(cds);
Transformer serializer = TransformerFactory.newInstance().newTransformer();
StringWriter stringOut = new StringWriter();
serializer.transform(new DOMSource(doc), new StreamResult(stringOut));
System.out.println(stringOut.toString());
Mapping.xml
<mapping>
<class name="com.bear.poc.CDS" >
<map-to xml="Envelope" />
<field name="activity" type="java.lang.String" xmlns="OTC_RM_09-Feb-2004">
<bind-xml name="Activity" location="Header/OTC_RM/Manifest/TradeMsg" node="element"/>
</field>
<field name="status" type="java.lang.String" xmlns="OTC_RM_09-Feb-2004">
<bind-xml name="Status" location="Header/OTC_RM/Manifest/TradeMsg" node="element"/>
</field>
<field name="transactionType" type="java.lang.String" xmlns="OTC_RM_09-Feb-2004">
<bind-xml name="TransType" location="Header/OTC_RM/Manifest/TradeMsg" node="element"/>
</field>
</class>
</mapping>
<class name="com.bear.poc.CDS" >
<map-to xml="Envelope" />
<field name="activity" type="java.lang.String" xmlns="OTC_RM_09-Feb-2004">
<bind-xml name="Activity" location="Header/OTC_RM/Manifest/TradeMsg" node="element"/>
</field>
<field name="status" type="java.lang.String" xmlns="OTC_RM_09-Feb-2004">
<bind-xml name="Status" location="Header/OTC_RM/Manifest/TradeMsg" node="element"/>
</field>
<field name="transactionType" type="java.lang.String" xmlns="OTC_RM_09-Feb-2004">
<bind-xml name="TransType" location="Header/OTC_RM/Manifest/TradeMsg" node="element"/>
</field>
</class>
</mapping>
Output
<?xml version="1.0"
encoding="UTF-8"?>
<env:Envelope xmlns:rm="OTC_RM_09-Feb-2004" xmlns:mtc="OTC_Matching_09-Feb-2004" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:fpml="http://www.fpml.org/2004/FpML-4-1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="OTC_RM_09-Feb-2004 /xmls/OTC/OTC_RM_09-Feb-2004.xsd
OTC_Matching_09-Feb-2004 /xmls/OTC/OTC_Matching_09-Feb-2004.xsd
http://schemas.xmlsoap.org/soap/envelope/ /xmls/OTC/soap-envelope.xsd">
<env:Header>
<OTC_RM xmlns="OTC_RM_09-Feb-2004">
<Manifest>
<TradeMsg>
<Activity>None</Activity> <!-- I WANT TO REPLACE THE VALUES HERE (IN BOLD) -->
<Status>None</Status>
<TransType>None</TransType>
<ProductType>None</ProductType>
<Submitter>
<partyTradeIdentifier>
<fpml:partyReference href=""/>
<fpml:tradeId tradeIdScheme="TradeRefNbr">None</fpml:tradeId>
</partyTradeIdentifier>
</Submitter>
</TradeMsg>
<MsgId>None</MsgId>
</Manifest>
<Delivery>
<RouteInfo>
<From>None</From>
<To>DTCC</To>
</RouteInfo>
<RouteHist>
<Route>
<RouteAddress>www.requestoraddress.com</RouteAddress>
<ReceiveTime>2002-09-24T18:08:40.335-05:00</ReceiveTime>
<ReleaseTime>2002-09-24T18:08:40.335-05:00</ReleaseTime>
</Route>
</RouteHist>
</Delivery>
</OTC_RM>
</env:Header>
</env:Envelope>
<Envelope> <!-- INSTEAD POPULATING THE ONE FROM THE TOP, CASTOR CREATED THESE NEW TAGS -->
<Header>
<OTC_RM>
<Manifest>
<TradeMsg>
<ns1:Activity xmlns:ns1="OTC_RM_09-Feb-2004">New</ns1:Activity>
<ns2:Status xmlns:ns2="OTC_RM_09-Feb-2004">Submit</ns2:Status>
<ns3:TransType xmlns:ns3="OTC_RM_09-Feb-2004">Trade</ns3:TransType>
</TradeMsg>
</Manifest>
</OTC_RM>
</Header>
</Envelope>
<env:Envelope xmlns:rm="OTC_RM_09-Feb-2004" xmlns:mtc="OTC_Matching_09-Feb-2004" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:fpml="http://www.fpml.org/2004/FpML-4-1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="OTC_RM_09-Feb-2004 /xmls/OTC/OTC_RM_09-Feb-2004.xsd
OTC_Matching_09-Feb-2004 /xmls/OTC/OTC_Matching_09-Feb-2004.xsd
http://schemas.xmlsoap.org/soap/envelope/ /xmls/OTC/soap-envelope.xsd">
<env:Header>
<OTC_RM xmlns="OTC_RM_09-Feb-2004">
<Manifest>
<TradeMsg>
<Activity>None</Activity> <!-- I WANT TO REPLACE THE VALUES HERE (IN BOLD) -->
<Status>None</Status>
<TransType>None</TransType>
<ProductType>None</ProductType>
<Submitter>
<partyTradeIdentifier>
<fpml:partyReference href=""/>
<fpml:tradeId tradeIdScheme="TradeRefNbr">None</fpml:tradeId>
</partyTradeIdentifier>
</Submitter>
</TradeMsg>
<MsgId>None</MsgId>
</Manifest>
<Delivery>
<RouteInfo>
<From>None</From>
<To>DTCC</To>
</RouteInfo>
<RouteHist>
<Route>
<RouteAddress>www.requestoraddress.com</RouteAddress>
<ReceiveTime>2002-09-24T18:08:40.335-05:00</ReceiveTime>
<ReleaseTime>2002-09-24T18:08:40.335-05:00</ReleaseTime>
</Route>
</RouteHist>
</Delivery>
</OTC_RM>
</env:Header>
</env:Envelope>
<Envelope> <!-- INSTEAD POPULATING THE ONE FROM THE TOP, CASTOR CREATED THESE NEW TAGS -->
<Header>
<OTC_RM>
<Manifest>
<TradeMsg>
<ns1:Activity xmlns:ns1="OTC_RM_09-Feb-2004">New</ns1:Activity>
<ns2:Status xmlns:ns2="OTC_RM_09-Feb-2004">Submit</ns2:Status>
<ns3:TransType xmlns:ns3="OTC_RM_09-Feb-2004">Trade</ns3:TransType>
</TradeMsg>
</Manifest>
</OTC_RM>
</Header>
</Envelope>
*********************************************************************** Bear Stearns is not responsible for any recommendation, solicitation, offer or agreement or any information about any transaction, customer account or account activity contained in this communication. ***********************************************************************
