In my xml, i have <ns5:Name>mil & carbon</ns5:Name>
From my java code i am retrieving that value by
public class MasterdataParser extends MasterdataBaseParser {
protected MasterdataParser(InputStream response) {
super(response);
}
public MasterData parse() {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
MasterData masterData;
try {
DocumentBuilder builder = factory.newDocumentBuilder();
Document dom = builder.parse(this.getInputStream());
Element root = dom.getDocumentElement();
masterData = new MasterData();
NodeList list;
Element element;
NodeList childNodeList;
Node node;
String nodeName;
list = root.getElementsByTagName(PREFIX+CATEGORY);
for (int i=0;i<list.getLength();i++){
element = (Element) list.item(i);
childNodeList = element.getChildNodes();
Category category = new Category();
for (int j = 0; j < childNodeList.getLength(); j++) {
node = childNodeList.item(j);
nodeName = node.getNodeName();
if (nodeName.equalsIgnoreCase(PREFIX+CATEGORY_ID)) {
try{
category.setId(node.getFirstChild().getNodeValue());
} catch (NullPointerException ex) {
category.setId(null);
}
}
if (nodeName.equalsIgnoreCase(PREFIX+CATEGORY_NAME)) {
try{
// System.out.println("Masterdataparser category name html "+Html.fromHtml(node.getFirstChild().getNodeValue())); // Not worked
System.out.println("URL Decoder "+URLDecoder.decode(node.getFirstChild().getNodeValue(), "UTF-8")); // Not worked
category.setName(node.getFirstChild().getNodeValue());
} catch (NullPointerException ex) {
category.setName(null);
}
}
}
public abstract class MasterdataBaseParser implements MasterdataParserInterface {
static final String CATEGORY = "Category";
static final String CATEGORY_ID = "Id";
static final String CATEGORY_NAME = "Name";
final InputStream response;
protected MasterdataBaseParser(InputStream response){
this.response = response;
}
protected InputStream getInputStream() {
return response;
}
}
But it displays only "mil"
and it is not taking "&"
as "&"
. But i want to display "mil & carbon"
. How to do this one? Advance thanks for any help