2010-11-29 6 views
1
package com.converter; 

import java.io.IOException; 
import java.net.URI; 
import java.net.URL; 

import java.util.StringTokenizer; 

import javax.xml.parsers.DocumentBuilder; 
import javax.xml.parsers.DocumentBuilderFactory; 
import org.w3c.dom.Document; 

import org.w3c.dom.Node; 
import org.w3c.dom.NodeList; 
import org.xml.sax.SAXParseException; 
//import XmlReader.java; 
public class XMLReader { 
public Float value = 25f; 

public XMLReader(){ 
String parseString = ""; 


try { 

    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); 
    // dbf.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); 
    DocumentBuilder db = dbf.newDocumentBuilder(); 
    URI uri = new URI("http://themoneyconverter.com/USD/rss.xml"); 

    ****Document doc = db.parse(uri.toString());****  

    doc.getDocumentElement().normalize(); 
    NodeList nodeLst = doc.getElementsByTagName("description"); 
    int length = nodeLst.getLength(); 

    for (int s = 0; s < length; s++) { 
    Node fstNode = nodeLst.item(s); 
    parseString = fstNode.getTextContent(); 

    if(parseString.contains("Indian Rupee")){ 
     System.out.println(parseString); 
     StringTokenizer parser = new StringTokenizer(parseString,"="); 
     parser.nextToken(); 
     StringTokenizer parser1 = new StringTokenizer(parser.nextToken());  
     value = Float.valueOf(parser1.nextToken()); 
     System.out.println(value); 

    } 

    } 
    } catch (SAXParseException e) { 
    value = 30f; 
     e.printStackTrace(); 
    }catch (IOException e) { 
    value = 33f; 
     e.printStackTrace(); 
    }catch (Exception e) { 
     value = 32f; 
     e.printStackTrace(); 
    } 

} 

} 
+0

スタックトレースには何が表示されますか? –

+0

例外のメッセージは何ですか? –

答えて

1

を返して:

1 US Dollar = 45.92697 Indian Rupee 
45.92697 

は、だから私はあなたがリソースにアクセスするいくつかのネットワークの問題を持っていると思います。 )

乾杯;

など、ファイアウォールの設定、アンチウイルスプログラムを、確認するか、あなたはより多くの助けが必要な場合は、多分ここでスタックトレースを貼り付け!

+0

はうまくいった!どうもありがとうございました – ven

関連する問題