Java Reference
In-Depth Information
}
public XMLConnection(URL url) throws SQLException{
this.url = url;
xmlDoc = setXmlDoc(url);
}
public XMLConnection(String UrlString) throws SQLException{
try{
xmlDoc = setXmlDoc(new URL(UrlString));
}
catch (Exception e){
System.err.println(e);
}
}
private Document setXmlDoc(URL url){
Document xmlDoc = null;
// if the URL points to a file, and the file does not exist,
// create a new DOM document and return
if(url.getProtocol().equalsIgnoreCase("file")){
File f = new File(url.getFile());
if(!f.exists()){
String rootTag = f.getName();
rootTag =
rootTag.substring(rootTag.lastIndexOf("/")+1,
rootTag.indexOf("."));
return createXmlDoc(rootTag);
}
}
// otherwise parse the file to the DOM document
try{
InputStream s = url.openStream();
if(s!=null){
DOMParser p = new DOMParser();
p.parse(new InputSource(s));
xmlDoc = p.getDocument();
}
}catch (Exception e){
System.err.println(".."+e);
}
Search WWH ::




Custom Search