javaxmlmappingcastor

Castor XML Mapping:How to map a string child


Here is the xml:

  <infoAdicional>
    <campoAdicional nombre="correo:">edu.ec@hotmail.com</campoAdicional>
  </infoAdicional>

And here is my mapping file:

<class name="ec.eac.sitac.esigef.InfoAdicional">
    <map-to xml="infoAdicional" />

    <field name="campoAdicional" type="ec.eac.sitac.esigef.CampoAdicional">
        <bind-xml name="campoAdicional" node="element" />
    </field>
</class>

<class name="ec.eac.sitac.esigef.CampoAdicional">
    <map-to xml="campoAdicional" />

    <field name="nombre" type="java.lang.String">
        <bind-xml name="nombre" node="attribute" />
    </field>
</class>

When I try to convert the xml to a java object, an error appears. The reason is that I don´t know how to map the email text. This is not an element nor an attribute. How am I supposed to map this string?


Solution

  • I treated the field "campoAdicional" class as a String and I just ignored the attribute nombre="correo:".

    <class name="ec.eac.sitac.esigef.InfoAdicional">
        <map-to xml="infoAdicional" />
        <field name="campoAdicional" type="java.lang.String">
            <bind-xml name="campoAdicional" node="element" />
        </field>
    </class>