I'm a 
new Castor user and am ramping up on how it works.  I need to 
format Castor's XML output differently than how Castor seems 
to generate it by default.  In the following example XML output I'd 
like to know if it's possible to:
1.  Suppress 
the line break.
2.  Explicitly 
close <callInfo> rather than 
implicitly.
 
<?xml 
version="1.0" encoding="UTF-8"?>
<PatientContact 
MessageId="1234"><callInfo Patient_First_Name="John" 
Patient_Last_Name="Smith"/></PatientContact>
Thanks in 
advance.
-Matthew
Here is my 
mapping file:
<?xml 
version="1.0"?>
<!DOCTYPE mapping PUBLIC "-//EXOLAB/Castor Mapping DTD 
Version 1.0//EN" "http://castor.org/mapping.dtd";>
<mapping>
  
<class name="com.uht.example.PatientContact">
    
<map-to xml="PatientContact" />
    <field 
name="messageId" type="java.lang.String">
      
<bind-xml name="MessageId" node="attribute"  />
    
</field>  
    <field name="callInfo" 
type="com.uht.example.PatientCallInfo">
      
<bind-xml name="callInfo" node="element"  />
    
</field> 
  </class> 
  <class 
name="com.uht.example.PatientCallInfo">
    <field 
name="patientFirstName" 
type="java.lang.String">
      <bind-xml 
name="Patient_First_Name" node="attribute"  />
    
</field>     
    <field 
name="patientLastName" 
type="java.lang.String">
      <bind-xml 
name="Patient_Last_Name" node="attribute"  />
    
</field>                         

  </class>  
</mapping>
Here is 
main():
public 
static void main(String args[]){
 Mapping mapping = new 
Mapping();
 try {
   
mapping.loadMapping("src/main/resources/patientContactMapping.xml");
   
PatientCallInfo patient = new PatientCallInfo();
   
patient.setPatientFirstName("John");
   
patient.setPatientLastName("Smith");
 
   PatientContact 
patientContact = new PatientContact("1234", patient);
   StringWriter stringWriter = new 
StringWriter();
   Marshaller marshaller = new 
Marshaller(stringWriter);
   
marshaller.setMapping(mapping);
   
marshaller.marshal(patientContact);
   String s = 
stringWriter.toString();
   
System.out.println(s);
 }
 catch (Exception e) 
{
  System.out.println(e.toString());
 }
  
} 
 
Here is the 
PatientContact class:
public 
class PatientContact {
  private String messageId;
  private 
PatientCallInfo callInfo;
 
  
public PatientContact() 
{super();}
public 
PatientContact(String messageId, PatientCallInfo callInfo) 
{
 super();
 this.messageId = messageId;
 this.callInfo 
= callInfo;
}
public String getMessageId() {
 return 
messageId;
}
public void setMessageId(String messageId) 
{
 this.messageId = messageId;
}
public PatientCallInfo 
getCallInfo() {
 return callInfo;
}
public void 
setCallInfo(PatientCallInfo callInfo) {
 this.callInfo = 
callInfo;
}
}
 
Here is the 
PatientCallInfo class:
public 
class PatientCallInfo {
   private String patientFirstName 
="";
   private String patientLastName ="";
   
 public PatientCallInfo() 
{super();}
 
 public PatientCallInfo(String patientFirstName, 
String patientLastName) 
{
  super();
  this.patientFirstName = 
patientFirstName;
  this.patientLastName = 
patientLastName;
 }
 public String getPatientFirstName() 
{
  return patientFirstName;
 }
 public void 
setPatientFirstName(String patientFirstName) 
{
  this.patientFirstName = 
patientFirstName;
 }
 public String getPatientLastName() 
{
  return patientLastName;
 }
 public void 
setPatientLastName(String patientLastName) {
  this.patientLastName 
= patientLastName;
 }
}


      

Reply via email to