Title: Castor - CDATA tags in Mapping XML

      Hi,

      I have a class which has four attributes in it as follows.  I want the last attribute cData which is a string to be embedded within CDATA tags . How do I do this in the Mapping XML which the Marshall process uses? I have sent the java class which is the object, the class which sets the value for the object, the mapping XML and the output expected. In my example I get the cData attribute wrapped around element CDATA, but I want it the actual CDATA tags around the string . Any help is appreciated.

      public class ChartDataInfo

      {

          //attributes

          protected String appearanceName;

          protected String linkName;

          protected boolean isCurrentlySelected;

          protected String cData;

       

           /** Creates a new instance of ChartDataInfo */

          public ChartDataInfo() {

          }

          public String getAppearanceName() { return appearanceName; }

          public String getLinkName() { return linkName; }

          public boolean getIsCurrentlySelected() { return isCurrentlySelected; }

          public String getCData() { return cData; }

          public void setAppearanceName(String pValue) { appearanceName = pValue; }

          public void setLinkName(String pValue) { linkName = pValue; }

          public void setIsCurrentlySelected(boolean pValue) { isCurrentlySelected = pValue; }

          public void setCData(String pValue) { cData = pValue; }

            

      }


        CLASS which sets the value for ChartDataInfo class

public class ChartDataXML

{

    public static void main(String[] argv) {

       

        // Create a new MetaDataInfo

   

        ChartDataInfo mChartDataInfo = new ChartDataInfo();

        mChartDataInfo.setAppearanceName("TFLINBAR");

        mChartDataInfo.setLinkName("Line-BAR");

        mChartDataInfo.setIsCurrentlySelected(true);

        mChartDataInfo.setCData("charthtml");

       

                     // write it out as XML

                String encoding = "ISO-8859-1";

          

            String mMapping = "ChartDataMapping.xml";

           

                StringBuffer mStrBuf = MarshalBean.generateBOXML(mMapping, mChartDataInfo);

           

            System.out.println(mStrBuf);     

    }

}


      Mapping FILE

      <!DOCTYPE databases PUBLIC

        "-//EXOLAB/Castor Mapping DTD Version 1.0//EN"

        "http://castor.exolab.org/mapping.dtd">

      <mapping>

        <description>ChartData Mapping</description>

        <class name="ChartDataInfo">

          <map-to xml="charts"/>

          <field name="appearanceName" >

            <bind-xml name="appearance_name" node="attribute"  location="chart/chart_html_fragments/fragment"/>

          </field>

          <field name="isCurrentlySelected">

            <bind-xml name="is_currently_selected" node="attribute"  location="chart/chart_html_fragments/fragment"/>

          </field>

          <field name="linkName">

            <bind-xml name="link_name" node="attribute"  location="chart/chart_html_fragments/fragment"/>

          </field>

          <field name="cData">

            <bind-xml name="CData" node="element" location="chart/chart_html_fragments/fragment"/>

          </field>

        </class>

      </mapping>


        Expected output

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

- <charts>

      - <chart>

          - <chart_html_fragments>

              - <fragment appearance_name="TFLINBAR" is_currently_selected="true" link_name="Line-BAR">

               <![CDATA[charthtml]]>

                </fragment>

           </chart_html_fragments>

        </chart>

 </charts>


      Thanks,

      Sarita

----------------------------------------------------------- 
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
        unsubscribe castor-user

Reply via email to