0

I have defined the following Child Element Model for my XML:

package com.xmlmapper.www.model;

import javax.xml.bind.annotation.XmlElement;

import org.apache.axis.description.ElementDesc;
import org.apache.axis.description.FieldDesc;

public class ApplicantAddressDetails  implements java.io.Serializable {
    private java.lang.String addressSegmentTag;

    private java.lang.String length;

    private java.lang.String tag;

    private java.lang.String addressLine1FieldLength;

    private java.lang.String addressLine1;

    private java.lang.String addressLine2FieldLength;

    private java.lang.String addressLine2;

    private java.lang.String addressLine3FieldLength;

    private java.lang.String addressLine3;

    private java.lang.String addressLine4FieldLength;

    private java.lang.String addressLine4;

    private java.lang.String addressLine5FieldLength;

    private java.lang.String addressLine5;

    private java.lang.String stateCode;

    private java.lang.String pinCodeFieldLength;

    private java.lang.String pinCode;

    private java.lang.String addressCategory;

    public ApplicantAddressDetails() {
    }
........//next section of  code 
}

If my address has & keyword then my XML is not getting mapped. What needs to be done so that XML can be mapped automatically? What are all other characters for which I can face such errors?

Salman Shaikh
  • 575
  • 1
  • 7
  • 24
  • Can you replace first the `&` sign by `&`, and after successful mapping replace it back? – Reporter May 02 '23 at 07:55
  • @Reporter the suggested solution works if I take my input XML as string first, encode it and then try to push/map in the XML. Here my problem is my API is directly taking input as XML only, so I want a solution where XMLElement itself handles such scenario – Salman Shaikh May 02 '23 at 11:37
  • Because you havn't posted an example of your xml, from a far view using the & sign as value is actually wrong. Most parsers complaines about it. Generating a valid xml, & signs must be replaced by & . – Reporter May 02 '23 at 11:52
  • @Reporter so can we conclude that special characters should be escaped before giving to XML Mapper and there is no function/feature/library which will do this for me? Initially I thought since my variable is String the address one, XML take the entire string and map it to the String Variable or Tag – Salman Shaikh May 02 '23 at 11:54
  • Yes, I think so. – Reporter May 02 '23 at 11:56

0 Answers0