File file = new File(filePath);
Document document = reader.read(file);// 读取XML文件
Element root = document.getRootElement();// 得到根节点
Element select = root.element("select");
for (Iterator i = select.nodeIterator(); i.hasNext();) {
Object obj = i.next();
String content = "";
if (obj instanceof Text) {
content = ((Text)obj).getText().replaceAll("\n", "").trim();
java源文件解析建一个Student实体类封装数据
public static ListStudent readXml() {
ListStudent list = new ArrayListStudent();
//定义一个a href="https://www.04ip.com/post/;tn=44039180_cprfenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1Y3uhnvryDYrjIBPyDYn1Rv0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6K1TL0qnfK1TL0z5HD0IgF_5y9YIZ0lQzqlpA-bmyt8mh7GuZR8mvqVQL7dugPYpyq8Q1RznjcYn1TLnH04rjcYnjTvPf" target="_blank" class="baidu-highlight"dom解析/a器工厂实例
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
try {
//由工厂实例得到一个a href="https://www.04ip.com/post/;tn=44039180_cprfenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1Y3uhnvryDYrjIBPyDYn1Rv0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6K1TL0qnfK1TL0z5HD0IgF_5y9YIZ0lQzqlpA-bmyt8mh7GuZR8mvqVQL7dugPYpyq8Q1RznjcYn1TLnH04rjcYnjTvPf" target="_blank" class="baidu-highlight"dom解析/a器
DocumentBuilder dom = factory.newDocumentBuilder();
//找到a href="https://www.04ip.com/post/;tn=44039180_cprfenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1Y3uhnvryDYrjIBPyDYn1Rv0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6K1TL0qnfK1TL0z5HD0IgF_5y9YIZ0lQzqlpA-bmyt8mh7GuZR8mvqVQL7dugPYpyq8Q1RznjcYn1TLnH04rjcYnjTvPf" target="_blank" class="baidu-highlight"xml文档/a
File file=new File("src/com/jereh/ch05/Students.xml");
Document doc=dom.parse(file);
【java代码编写公安解析 java解析geojson】//
Element root = doc.getDocumentElement();
NodeList stuNodeList = root.getChildNodes();
for (int i = 0; istuNodeList.getLength(); i++) {
Node stu = stuNodeList.item(i);
Student student = new Student();
if (stu != nullstu.getNodeType() == Node.ELEMENT_NODE) {
// System.out.println(stu);
Element stuElement = (Element) stu;
student.setNo(stuElement.getAttribute("id"));
// stu.getAttributes().getNamedItem(null);
// Element stu=(Element)stuNodeList
NodeList info = stuElement.getChildNodes();
for (int j = 0; jinfo.getLength(); j++) {
info.item(j).getNodeName();
Node n = info.item(j);
if ("name".equals(n.getNodeName())) {
// n.getFirstChild().getNodeValue();
student.setName(n.getLastChild().getNodeValue());
} else if ("age".equals(n.getNodeName())) {
student.setAge(Integer.parseInt(n.getFirstChild()
.getNodeValue()));
}
list.add(student);
}
}
}
} catch (ParserConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SAXException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// System.out.println(root.getNodeValue());
return list;
}
关于java代码编写公安解析和java解析geojson的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息 , 记得收藏关注本站 。
推荐阅读
- 手机黑白单机游戏,手机玩黑白机游戏
- 世界沙盒下载,创游世界下载
- 游戏开发巨头游戏怎么搭配,游戏开发巨头匹配表
- asp.net登陆画面设计,aspnet登录界面代码
- java图片随机显示代码 java自动生成图片
- 百兆路由器怎么设置,百兆路由器怎么设置网速最快
- pg数据库当前系统时间,pg数据库时间格式转换
- 网站平台制作公司,做网站制作公司
- linux蓝牙操作命令 linux如何打开蓝牙