易截截图软件、单文件、免安装、纯绿色、仅160KB

java对XML文件的解析、节点的增加、删除操作总结

先贴代码吧
感谢:http://xranming.blog.163.com/blog/static/24204952009914104148872/
 http://www.diybl.com/course/3_program/java/javajs/20090303/157541.html
1、java代码:
主要采用dom来进行操作
java对xml操作有四种方法:http://passmatlab.bokee.com/3455905.html
 package test;
import java.io.IOException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.w3c.dom.Text;
import org.xml.sax.SAXException;
public class XmlOprate {
 Document doc;
 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
 DocumentBuilder builder;
 NodeList imags;
 String path;
 
 public NodeList getImags() {
  return imags;
 }
 public void setImags(NodeList imags) {
  this.imags = imags;
 }
 
 /**
  * 构造方法
  * @param path:xml文件的路径
  * @param nodes:要解析的xml节点名称
  */
 public XmlOprate(String path) {
  super();
  this.path = path;
  System.out.println(System.getProperty("user.dir"));
 }
 /**
  * 解析XML
  * @param path
  */
 public  void readXml(){
  try {
   builder = factory.newDocumentBuilder();
   Document doc=builder.parse(path);
   doc.normalize();
   
   NodeList imags =doc.getElementsByTagName("imags");
   this.setImags(imags);
   for (int i=0;


相关文档:

java中的foreach用法

 import java.util.*;
public class ForeachExample {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Random r = new Random();
int[] x = new int[10];
for (int i = 0; i < x.length; i++) {
x[i] = r.nextInt(100);
}
/ ......

java中this关键字用法

 /**
* this关键字用法
*/
public class Flower {

int petalCount = 0;
String s = "initial value";

Flower(int petals){
petalCount = petals;
System.out.println("Constructor with one int arg");
}

Flower(String ss){
System.out.println("Constr ......

Name java:comp is not bound in this Context

 
javax.naming.NameNotFoundException: Name jdbc is not bound in this Context
在tomcat中发布web项目,可能是因为spring中配置了jndi(只配置了jndi,其他的有工具包封装了)。
启动的时候报错(在项目目录下,在tomcat中配置context指向项目目录就没问题,打包发布到
tomcat就报错了),抛的异常是:
jav ......

关于 java swing 中的repaint 和 revalidate 含义

   repaint 对组件进行重绘,比如一个panel,当你remove掉panel里面的一个组件时,你必须调用repaint方法才能对panel进行重绘,进行刷新,你想要删除的组件才能在界面上消失。
   revalidate 对组件进行验证,比如一个panel,当你remove掉panel里面的一个组件时,当你调用revalidate方法后,panel的布 ......

Java中static、this、super、final 的用法

 本篇旨在帮助准备学习Java以及刚接触Java的朋友认识、掌握和使用static、this、super、final这几个关键字的使用。Java博大精深,我也是一位正在学习和使用Java的爱好者,文中难免有不妥之处,欢迎指正。
一、static
 请先看下面这段程序:
public class Hello{
  public static void main(String[] args){ ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号