下面parse方法的源码
/**
* Parse the content of the specified file using this Digester. Returns
* the root element from the object stack (if any).
*
* @param file File containing the XML data to be parsed
*
* @exception IOException if an input/output error occurs
* @exception SAXException if a parsing exception occurs
*/
public Object parse(File file) throws IOException, SAXException { configure();
InputSource input = new InputSource(new FileInputStream(file));
input.setSystemId(file.toURL().toString());
getXMLReader().parse(input);
return (root); }
/**
* Parse the content of the specified input source using this Digester.
* Returns the root element from the object stack (if any).
*
* @param input Input source containing the XML data to be parsed
*
* @exception IOException if an input/output error occurs
* @exception SAXException if a parsing exception occurs
*/
public Object parse(InputSource input) throws IOException, SAXException {
configure();
getXMLReader().parse(input);
return (root); }
/**
* Parse the content of the specified input stream using this Digester.
* Returns the root element from the object stack (if any).
*
* @param input Input stream containing the XML data to be parsed
*
* @exception IOException if an input/output error occurs
* @exception SAXException if a parsing exception occurs
*/
public Object parse(InputStream input) throws IOException, SAXException { configure();
InputSource is = new InputSource(input);
getXMLReader().parse(is);
return (root); }
/**
* Parse the content of the specified reader using this Digester.
* Returns the root element from the object stack (if any).
*
* @param reader Reader containing the XML data to be parsed
*
* @exception IOException if an input/output error occurs
* @exception SAXException if a parsing exception occurs
*/
public Object parse(Reader reader) throws IOException, SAXException { configure();
InputSource is = new InputSource(reader);
getXMLReader().parse(is);
return (root); }
/**
* Parse the content of the specified URI using this Digester.
* Returns the root element from the object stack (if any).
*
* @param uri URI containing the XML data to be parsed
*
* @exception IOException if an input/output error occurs
* @exception SAXException if a parsing exception occurs
*/
public Object parse(String uri) throws IOException, SAXException { configure();
InputSource is = new InputSource(uri);
getXMLReader().parse(is);
return (root); }我使用时的代码:try {
File file = new File(fileName);
// if (!file.exists()){
// file.createNewFile();
// }
project = (Project)digester.parse(file);
} catch (IOException e) {
throw new XMLException("can not found xml file");
} catch (SAXException e) {
throw new XMLException("parse xml file error"+e.getMessage());
}
验证文件是存在的,
但是执行parse(file)的时候出现“Connection refused: connect”
异常。
/**
* Parse the content of the specified file using this Digester. Returns
* the root element from the object stack (if any).
*
* @param file File containing the XML data to be parsed
*
* @exception IOException if an input/output error occurs
* @exception SAXException if a parsing exception occurs
*/
public Object parse(File file) throws IOException, SAXException { configure();
InputSource input = new InputSource(new FileInputStream(file));
input.setSystemId(file.toURL().toString());
getXMLReader().parse(input);
return (root); }
/**
* Parse the content of the specified input source using this Digester.
* Returns the root element from the object stack (if any).
*
* @param input Input source containing the XML data to be parsed
*
* @exception IOException if an input/output error occurs
* @exception SAXException if a parsing exception occurs
*/
public Object parse(InputSource input) throws IOException, SAXException {
configure();
getXMLReader().parse(input);
return (root); }
/**
* Parse the content of the specified input stream using this Digester.
* Returns the root element from the object stack (if any).
*
* @param input Input stream containing the XML data to be parsed
*
* @exception IOException if an input/output error occurs
* @exception SAXException if a parsing exception occurs
*/
public Object parse(InputStream input) throws IOException, SAXException { configure();
InputSource is = new InputSource(input);
getXMLReader().parse(is);
return (root); }
/**
* Parse the content of the specified reader using this Digester.
* Returns the root element from the object stack (if any).
*
* @param reader Reader containing the XML data to be parsed
*
* @exception IOException if an input/output error occurs
* @exception SAXException if a parsing exception occurs
*/
public Object parse(Reader reader) throws IOException, SAXException { configure();
InputSource is = new InputSource(reader);
getXMLReader().parse(is);
return (root); }
/**
* Parse the content of the specified URI using this Digester.
* Returns the root element from the object stack (if any).
*
* @param uri URI containing the XML data to be parsed
*
* @exception IOException if an input/output error occurs
* @exception SAXException if a parsing exception occurs
*/
public Object parse(String uri) throws IOException, SAXException { configure();
InputSource is = new InputSource(uri);
getXMLReader().parse(is);
return (root); }我使用时的代码:try {
File file = new File(fileName);
// if (!file.exists()){
// file.createNewFile();
// }
project = (Project)digester.parse(file);
} catch (IOException e) {
throw new XMLException("can not found xml file");
} catch (SAXException e) {
throw new XMLException("parse xml file error"+e.getMessage());
}
验证文件是存在的,
但是执行parse(file)的时候出现“Connection refused: connect”
异常。
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货