繁体   English   中英

DocumentBuilder.parse(String Uri)返回IOException

[英]DocumentBuilder.parse(String Uri) is returning the IOException

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();
   }

}

}

这是我的输出工作:

1 US Dollar = 45.92697 Indian Rupee
45.92697

因此,我想您在访问资源时遇到了一些网络问题。 检查防火墙设置,防病毒程序等。

如果您需要更多帮助,也可以在此处粘贴堆栈跟踪信息;)

干杯!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM