Php利用java解析xml


ing path=null;
public String XmlFileName=null;
public SAXBuilder sax=null;
public Document doc=null;
public Element root=null;
public List xlist=null;
public Element e=null;
public Element value=null;

public String getTest(){
return new String("haha");
}
public JavaXml(){

}

public String init(){

InputStream is = getClass().getResourceAsStream("global.properties");
Properties dbProps = new Properties();
try {
dbProps.load( is ) ;
}
catch ( Exception e ) {
return ("error file");
}
this.path=dbProps.getProperty("XmlPath");
return ("ok");
}

public void get(int child){
this.e=(Element)xlist.get(child);
}
public String getValue(String name){
this.value=e.getChild(name);
return this.value.getText();
}
public void setValue(String name,String value)throws Exception{
this.value=e.getChild(name);
this.value.setText(value);
XMLOutputter xmlout=new XMLOutputter();
xmlout.output(doc,new FileOutputStream(path+XmlFileName));
}

public void Parse(String XmlFileName)
throws Exception
{
this.XmlFileName=XmlFileName;
this.sax=new SAXBuilder();
this.doc=sax.build(new FileInputStream(path+XmlFileName));
this.root=doc.getRootElement();
this.xlist=root.getChildren();
}

}


如果还有什么不懂的请跟贴,这样子对新手不知道是更麻烦还是更方便了,请大家发表自己的意见,如果各位觉得可以的话我将继续完善那个JAVA类,提供更多的解析XML的功能。
Copyright © 2008 chengduxinxi.com All Rights Reserved PHP编程开发 由朝夕网络维护