I have a function that reads XML and it works 100%, the problem is that when I try to read an XML that is online on my server I can not.
Follow the code below:
public int lerXml() throws JDOMException, IOException, URISyntaxException {
URL url = new URL("http://br728.teste.website/~ayzac296/smh/xml.xml");
File f = new File(url.toURI());
SAXBuilder sb = new SAXBuilder();
Document d;
try {
d = sb.build(f);
} catch (Exception e) {
System.out.println(e);
return 0;
}
Element mural = d.getRootElement();
List elements = mural.getChildren();
Iterator i = elements.iterator();
while (i.hasNext()) {
Element element = (Element) i.next();
if (Double.parseDouble(element.getChildText("tempo")) >= mediaPlayer.getCurrentTime().toSeconds()) {
//System.out.println("Nome:" + element.getChildText("nome"));
//System.out.println("Tempo:" + element.getChildText("tempo"));
System.out.println("Menssagem:" + element.getChildText("conteudo"));
}
}
return 1;
}
It is showing the following error:
Exception in thread "Thread-179" java.lang.IllegalArgumentException: URI scheme is not "file"
I'm having trouble turning the URL into File.
Thank you.