xml⽣成java对象_将XML⽂件转换为JAVA对象XML⽂件内容
?>
id="1000000002">
ename=""/>
ename=""/>
ename=""/>
ename=""/>
ename=""/>
ename=""/>
ename=""/>
ename=""/>
totalPropTypeName="Skill Prop">
ename=""/>
ename=""/>
ename=""/>
ename=""/>
totalPropTypeName="Function Prop">
ename=""/>
ename=""/>
ename=""/>
ename=""/>
ename=""/>
java xml是什么
定义JAVA对象类[root]
package l.bean;
import java.util.ArrayList;
import java.util.List;
import org.dom4j.Element;
public class CONRootElement {
private List propLst = new ArrayList();
public void newRootElement(Element rootElm,
CONRootElement rel) {
List itemLst =
rootElm.elements();
for (int i = 0; i
< itemLst.size(); i++) {
Element elem
= (Element) (i);
if
(Name().equals(XML_GAME)) { CONGameElement
prope = new CONGameElement();
prope.initPropElement(elem,
rel.propLst, prope);
}
}
}
public List getPropLst() {
return propLst;
}
public void setPropLst(List propLst) {
this.propLst =
propLst;
}
public static String XML_ROOT = "root";
public static String XML_GAME = "Game"; public static String XML_ID = "id";
public static String XML_PROPFILE = "PropFile";
public static String XML_FILENAME = "fileName";
public static String XML_TOTALPROPTYPE = "totalPropType";
public static String XML_TOTALPROPNAME = "totalPropTypeName";
public static String XML_PROPTYPE = "PropType";
public static String XML_TYPE = "type";
public static String XML_CNAME =
"cname";
public static String XML_ENAME = "ename";
}
定义JAVA对象类[Game]
package l.bean;
import java.util.ArrayList;
import java.util.List;
import org.dom4j.Element;
public class CONGameElement {
private String id = "";
private List propFileLst = new
ArrayList();
public void initPropElement(Element elem, List
propLst, CONGameElement prope) {
prope.setId(elem.attribute(CONRootElement.XML_ID).getValue()); List itemLst =
elem.elements();
for (int i = 0; i
< itemLst.size(); i++) {
Element
chidelem = (Element) (i);
if
(Name().equals(CONRootElement.XML_PROPFILE)) {
CONPropFileElement
conPropeFile = new CONPropFileElement();
conPropeFile.initPropElement(chidelem,
prope.propFileLst, conPropeFile);
}
}
propLst.add(prope);
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
}
定义JAVA对象类[PropFile]
package l.bean;
import java.util.ArrayList;
import java.util.List;
import org.dom4j.Element;
public class CONPropFileElement {
private String filename = "";
private String totalPorpType = "";
private String totalPorpTypeName = "";
private List propTypeLst = new ArrayList();
public void initPropElement(Element elem, List
propFileLst,
CONPropFileElement
conPropeFile) {
conPropeFile.setFilename(elem.attribute(CONRootElement.XML_FILENAME) .getValue());
conPropeFile.setTotalPorpType(elem.attribute(
CONRootElement.XML_TOTALPROPTYPE).getValue());
conPropeFile.setTotalPorpTypeName(elem.attribute(
CONRootElement.XML_TOTALPROPNAME).getValue());
List itemLst =
elem.elements();
for (int i = 0; i
< itemLst.size(); i++) {
Element
chidelem = (Element) (i);
if
(Name().equals(CONRootElement.XML_PROPTYPE))
{
CONPropTypeElement
prope = new CONPropTypeElement(); prope
.initPropElement(chidelem, conPropeFile.propTypeLst,
prope);
}
}
propFileLst.add(conPropeFile);
}
public String getFilename() {
return filename;
}
public void setFilename(String filename) {
this.filename =
filename;
}
public String getTotalPorpType() {
return totalPorpType;
}
public void setTotalPorpType(String totalPorpType) {
totalPorpType;
}
public String getTotalPorpTypeName() { return
totalPorpTypeName;
}
public void setTotalPorpTypeName(String totalPorpTypeName) {

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。