Some times the response ,came from webservice may contains <,>.
Inthis case You have to convert '<' as '<' and '>' as '>'.
public static String validateXml(String xml)
{
int offset=0;
StringBuffer temp=new StringBuffer();
try{
while(xml.indexOf("<",offset)!=-1||xml.indexOf(">",offset)!=-1&&offset<xml.length()){
// if(Constants.LOG)Logger.info("Into < and & rt");
if((xml.indexOf("<",offset)<xml.indexOf(">",offset))&&(xml.indexOf("<",offset)!=-1)||((xml.indexOf(">",offset)==-1)&&(xml.indexOf("<",offset)!=-1))){
// if(Constants.LOG)Logger.info("Converting < into <");
temp.append(xml.substring(offset, xml.indexOf("<",offset)));
temp.append("<");
offset=xml.indexOf("<",offset)+"<".length();
}
else if((xml.indexOf(">",offset)<xml.indexOf("<",offset)&&(xml.indexOf(">",offset)!=-1))||((xml.indexOf("<",offset)==-1)&&(xml.indexOf(">",offset)!=-1))){
// if(Constants.LOG)Logger.info("Converting < into >");
temp.append(xml.substring(offset, xml.indexOf(">",offset)));
temp.append(">");
offset=xml.indexOf(">",offset)+">".length();
}
// if(Constants.LOG)Logger.info("offset is : "+offset);
}
if(offset<xml.length()){
temp.append(xml.substring(offset));
}
}catch (Exception e) {
// TODO: handle exception
//if(Constants.LOG)Logger.info("Array out of bound of exception");
}
xml=temp.toString();
return xml;
}
Inthis case You have to convert '<' as '<' and '>' as '>'.
public static String validateXml(String xml)
{
int offset=0;
StringBuffer temp=new StringBuffer();
try{
while(xml.indexOf("<",offset)!=-1||xml.indexOf(">",offset)!=-1&&offset<xml.length()){
// if(Constants.LOG)Logger.info("Into < and & rt");
if((xml.indexOf("<",offset)<xml.indexOf(">",offset))&&(xml.indexOf("<",offset)!=-1)||((xml.indexOf(">",offset)==-1)&&(xml.indexOf("<",offset)!=-1))){
// if(Constants.LOG)Logger.info("Converting < into <");
temp.append(xml.substring(offset, xml.indexOf("<",offset)));
temp.append("<");
offset=xml.indexOf("<",offset)+"<".length();
}
else if((xml.indexOf(">",offset)<xml.indexOf("<",offset)&&(xml.indexOf(">",offset)!=-1))||((xml.indexOf("<",offset)==-1)&&(xml.indexOf(">",offset)!=-1))){
// if(Constants.LOG)Logger.info("Converting < into >");
temp.append(xml.substring(offset, xml.indexOf(">",offset)));
temp.append(">");
offset=xml.indexOf(">",offset)+">".length();
}
// if(Constants.LOG)Logger.info("offset is : "+offset);
}
if(offset<xml.length()){
temp.append(xml.substring(offset));
}
}catch (Exception e) {
// TODO: handle exception
//if(Constants.LOG)Logger.info("Array out of bound of exception");
}
xml=temp.toString();
return xml;
}
No comments:
Post a Comment