我有一個java代碼,它解析xml文件以獲取主題的id,我想將此字符串轉換爲整數,我已經使用BigInteger但它不起作用:如何將字符串值的xml文件轉換爲整數
public void topicid(){
File inputFile = new File("D:\\Topic.xml");
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
try {
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(inputFile);
doc.getDocumentElement().normalize();
System.out.println("Root element :" + doc.getDocumentElement().getNodeName());
NodeList nList = doc.getElementsByTagName("top");
for (int temp = 0; temp < nList.getLength(); temp++) {
Node nNode = nList.item(temp);
System.out.println("----------------------------------------------------------------------------");
System.out.println("\n La requete :" + nNode.getNodeName());
if (nNode.getNodeType() == Node.ELEMENT_NODE) {
Element eElement = (Element) nNode;
String idtopic=eElement.getElementsByTagName("querytweettime").item(0).getTextContent();
System.out.println("l'id de la requete est:" + idtopic);
BigInteger idq= new BigInteger(idtopic);
System.out.println("l'id final de topic :" +idq);
}
所以,你想要一個整數,或者一個BigInteger? 「它不起作用」是什麼意思?你的輸入是什麼,你的期望輸出是什麼,你的實際輸出是什麼? –