public static Valute getValuteByValuteCh(String valuteCh, GetCursOnDateXMLResult result) throws Exception{ Valute answer = new Valute(); List<Object> list = result.getContent(); ElementNSImpl e = (ElementNSImpl) list.get(0); NodeList chCodeList = e.getElementsByTagName("VchCode"); int length = chCodeList.getLength(); boolean isFound = false; for (int i = 0; i< length; i++){ if (isFound) break; Node valuteChNode = chCodeList.item(i); TextImpl textimpl = (TextImpl)valuteChNode.getFirstChild(); String chVal = textimpl.getData(); if (chVal.equalsIgnoreCase(valuteCh)){ isFound = true; Node parent = valuteChNode.getParentNode(); NodeList nodeList = parent.getChildNodes(); int paramLength = nodeList.getLength(); for (int j=0; j<paramLength; j++){ Node currentNode = nodeList.item(j); String name = currentNode.getNodeName(); Node currentValue = currentNode.getFirstChild(); String value = currentValue.getNodeValue(); if (name.equalsIgnoreCase("Vname")){ answer.name = value; } if (name.equalsIgnoreCase("Vnom")){ answer.nom = new BigDecimal(value); } if (name.equalsIgnoreCase("Vcurs")){ answer.curs = new BigDecimal(value); } if (name.equalsIgnoreCase("Vcode")){ answer.code = Integer.parseInt(value); } if (name.equalsIgnoreCase("VchCode")){ answer.chCode = value; } } } } return answer; } 

Method parsit XML response web service qfr Xerces library used When launching an application on the server, an error occurs on the line ElementNSImpl e = (ElementNSImpl) list.get (0);

 java.lang.ClassCastException: com.sun.org.apache.xerces.internal.dom.ElementNSImpl cannot be cast to org.apache.xerces.dom.ElementImpl at com.naitos.WSUsing.GetCursOnDateResultParser.getValuteByValuteCh(GetCursOnDateResultParser.java:44) 
  • one
    Judging by the text of the error, you need to replace import org.apache.xerces.dom.ElementNSImpl with import com.sun.org.apache.xerces.internal.dom.ElementNSImpl - Regent

1 answer 1

There seems to be the wrong caste, but

 Element e = (Element) list.get(0);