javaxmlunmarshallingcastor

Ignoring fields when unmarshalling using Castor XML Mapping


I need to convert a XML to an object (Unmarshalling), but there is a field (tag) that I don´t want it to be mapped. I have been looking for an answer in StackOverFlow but only found how to convert an object to a XML (Marshalling) and I need to know about (Unmarshalling). Here is the XML:

<autorizacion>
    <estado>AUTORIZADO</estado>
    <numeroAutorizacion>9999999999999</numeroAutorizacion>
    <fechaAutorizacion>17/06/2015</fechaAutorizacion>
    <comprobante>
<comprobanteRetencion id="comprobante" version="1.0.0">
   <infoAdicional>
    <campoAdicional nombre="correo:">jeje@hotmail.com</campoAdicional>
  </infoAdicional>
<ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:etsi="http://uri.etsi.org/01903/v1.3.2#" Id="Signature89637">
<ds:KeyInfo Id="Certifixxxxxx0">
<ds:Modulus>
ppFiiWXmjvwteDiLvklh38gGypZ8moRjEhEijs0kfjpddd1NTJ5QWmNtgH8uVUP5aEduxPMYQPpg
</ds:Modulus>
</ds:KeyInfo>
</ds:Signature>
</comprobanteRetencion>
</comprobante>
</autorizacion>

I want to exclude the tag Signature from the unmarshalling process.

Herer is the mapping XML:

<class name="ec.eac.sitac.esigef.ComprobanteRetencion" auto-complete="true">
    <map-to xml="comprobanteRetencion" />
    <field name="infoAdicional" type="ec.eac.sitac.esigef.InfoAdicional">
        <bind-xml name="infoAdicional" node="element" />
    </field>
</class>

Solution

  • I removed the tag by using:

            DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
            DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
            Document doc = docBuilder.parse(xmlPath);
    
            Node node = xml.getElementsByTagName("comprobanteRetencion").item(0);
            Node signature = node.getLastChild();
            node.removeChild(signature);