求助
解决方案 »
- hibernate4 分页怎么用getHibernateTemplate().find(hql).size();
- MyBatis,select返回java.sql.ResultSet类型如何做到
- struts2 中如何通过配置文件连接数据库
- excel表如何导入sql2000,请高手指点一下!
- 关于JavaBean的使用问题
- 关于配置Tomcat的问题。。
- 先谢了!tomcat4.1.8下,ctx=(Context)ctx.lookup("java:/comp/env")为NULL,怎么办呢?
- 有多少人在用Netscape?
- 做多用户的网站流量分析系统!
- jsp的难题,有点难度!高手来看看!正确马上结贴!
- 关于Ajax.Request方法的URL长度问题
- 求bbs中的分页,最节省资源的!
* @param args
* @throws SAXException
* @throws ParserConfigurationException
* @throws IOException
*/
public static void main(String[] args) throws ParserConfigurationException,
SAXException, IOException { SAXParserFactory spf = SAXParserFactory.newInstance();
spf.setValidating(false);
spf.setFeature("http://xml.org/sax/features/namespace-prefixes", true);
spf.setFeature("http://xml.org/sax/features/namespaces", true);
SAXParser sp = spf.newSAXParser();
XMLReader xr = sp.getXMLReader(); xr.setContentHandler(new Sax());
xr.setErrorHandler(new Sax()); InputSource is = new InputSource("c:\\sax.xml");
xr.parse(is);
}
public void startDocument() throws SAXException { System.out.println("start to read xml");
}
public void endDocument() throws SAXException { System.out.println("end of reading xml");
}
public void startElement(String uri, String localName, String qName,
Attributes attributes) throws SAXException {// System.out.println("uri----" + uri);
// System.out.println("localName----" + localName);
// System.out.println("qName----" + qName);
// Method[] methods = attributes.getClass().getMethods();
// for (int i = 0; i < methods.length; i++) {
// Method method = methods[i];
// String name = method.getName();
// if (name.startsWith("get")) {
// Class[] param = method.getParameterTypes();
// if (param.length == 1 && param[0].isPrimitive()) {
// try {
// for (int j = 0; j < attributes.getLength(); j++) {
// String info = name
// + "----"
// + method.invoke(attributes,
// new Object[] { new Integer(j) });
// System.out.println(info);
// }
// } catch (IllegalArgumentException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// } catch (IllegalAccessException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// } catch (InvocationTargetException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// }
// }
// }
// System.out.println("----");
}
public void processingInstruction(String target, String data)
throws SAXException { System.out.println("target----" + target);
System.out.println("data----" + data);
}}
DOMParser parser=new DOMParser();
parser.parse(new InputSource(in));
Document doc=parser.getDocument();
然后使用doc.getElementsByTagName("*")获得所有xml中的元素;