沈海蓉,九脉修神下载,iphone imei查询
先简单说下前三种方式:
dom方式:个人理解类似.net的xmldocument,解析的时候效率不高,占用内存,不适合大xml的解析;
sax方式:基于事件的解析,当解析到xml的某个部分的时候,会触发特定事件,可以在自定义的解析类中定义当事件触发时要做得事情;个人感觉一种很另类的方式,不知道.net体系下是否有没有类似的方式?
stax方式:个人理解类似.net的xmlreader方式,效率高,占用内存少,适用大xml的解析;
不过sax方式之前也用过,本文主要介绍jaxb,这里只贴下主要代码:
import org.xml.sax.attributes;
public class configitembase {
private static dateformat dateformat = new simpledateformat("yyyy-mm-dd hh:mm:ss");
public configitembase() {
}
/**
* 目前只支持几种常用类型 如果需要支持其他类型,请修改这里的代码
*
* @param attributes
*/
public configitembase(attributes attributes) {
class<?> cls = this.getclass();
field[] fields = cls.getdeclaredfields();
for (field field : fields) {
string fieldtype = field.gettype().getsimplename();
for (int i = 0; i < attributes.getlength(); i++) {
if (attributes.getqname(i).equalsignorecase(field.getname())) {
field.setaccessible(true);
try {
if (fieldtype.equalsignorecase("string")) {
field.set(this, attributes.getvalue(attributes.getqname(i)));
} else if (fieldtype.equalsignorecase("integer")) {
field.set(this, integer.valueof(attributes.getvalue(attributes.getqname(i))));
} else if (fieldtype.equalsignorecase("double")) {
field.set(this, double.valueof(attributes.getvalue(attributes.getqname(i))));
} else if (fieldtype.equalsignorecase("date")) {
field.set(this, getdate(attributes.getvalue(attributes.getqname(i))));
} else {
system.out.println("warning:unhandler field(" + field.getname() + "-" + fieldtype + ")");
}
} catch (illegalargumentexception e) {
e.printstacktrace();
} catch (illegalaccessexception e) {
e.printstacktrace();
}
break;
}
}
}
}
public string tostring() {
string result = "";
class<?> cls = this.getclass();
string classnamestring = cls.getname();
result += classnamestring.substring(classnamestring.lastindexof('.') + 1, classnamestring.length()) + ":";
field[] fields = cls.getdeclaredfields();
for (field field : fields) {
try {
result += field.getname() + "=" + field.get(this) + ";";
} catch (illegalargumentexception e) {
e.printstacktrace();
} catch (illegalaccessexception e) {
e.printstacktrace();
}
}
return result;
}
/**
* 处理时间类型属性(时间格式要求为:yyyy-mm-dd hh:mm:ss)
*
* @param datestring
* @return
*/
private static date getdate(string datestring) {
date date = null;
try {
date = dateformat.parse(datestring);
} catch (parseexception e) {
e.printstacktrace();
}
return date;
}
}
@xmlelement(name = "oprnumb")
private string oprnumb = "";
@xmlelement(name = "subscriptioninfo")
private subscriptioninfo subscriptioninfo;
public batchsyncorderrelationreqbody(){
}
public batchsyncorderrelationreqbody(string oprnumb, subscriptioninfo subscriptioninfo) {
this.oprnumb = oprnumb;
this.subscriptioninfo = subscriptioninfo;
}
public string getoprnumb() {
return this.oprnumb;
}
public void setoprnumb(string oprnumb) {
this.oprnumb = oprnumb;
}
public subscriptioninfo getsubscriptioninfo() {
return this.subscriptioninfo;
}
public void setsubscriptioninfo(subscriptioninfo subscriptioninfo) {
this.subscriptioninfo = subscriptioninfo;
}
}
@xmlelement(name = "actionid")
private string actionid = "";
@xmlelement(name = "brand")
private string brand = "";
@xmlelement(name = "efftime")
private string efftime = "";
@xmlelement(name = "expiretime")
private string expiretime = "";
@xmlelement(name = "feeuser_id")
private string feeuserid = "";
@xmlelement(name = "destuser_id")
private string destuserid = "";
@xmlelement(name = "actionreasonid")
private string actionreasonid = "";
@xmlelement(name = "servtype")
private string servtype = "";
@xmlelement(name = "subservtype")
private string subservtype = "";
@xmlelement(name = "spid")
private string spid = "";
@xmlelement(name = "spservid")
private string spservid = "";
@xmlelement(name = "accessmode")
private string accessmode = "";
@xmlelement(name = "feetype")
private string feetype = "";
public subscriptioninfo() {
}
public subscriptioninfo(
string oprtime,
string actionid,
string brand,
string efftime,
string expiretime,
string feeuserid,
string destuserid,
string actionreasonid,
string servtype,
string subservtype,
string spid,
string spservid,
string accessmode,
string feetype) {
this.oprtime = oprtime;
this.actionid = actionid;
this.brand = brand;
this.efftime = efftime;
this.expiretime = expiretime;
this.feeuserid = feeuserid;
this.destuserid = destuserid;
this.actionreasonid = actionreasonid;
this.servtype = servtype;
this.subservtype = subservtype;
this.spid = spid;
this.spservid = spservid;
this.accessmode = accessmode;
this.feetype = feetype;
}
public string getoprtime() {
return this.oprtime;
}
public void setoprtime(string oprtime) {
this.oprtime = oprtime;
}
public string getactionid() {
return this.actionid;
}
public void setactionid(string actionid) {
this.actionid = actionid;
}
public string getbrand() {
return this.brand;
}
public void setbrand(string brand) {
this.brand = brand;
}
public string getefftime() {
return this.efftime;
}
public void setefftime(string efftime) {
this.efftime = efftime;
}
public string getexpiretime() {
return this.expiretime;
}
public void setexpiretime(string expiretime) {
this.expiretime = expiretime;
}
public string getfeeuserid() {
return this.feeuserid;
}
public void setfeeuserid(string feeuserid) {
this.feeuserid = feeuserid;
}
public string getdestuserid() {
return this.destuserid;
}
public void setdestuserid(string destuserid) {
this.destuserid = destuserid;
}
public string getactionreasonid() {
return this.actionreasonid;
}
public void setactionreasonid(string actionreasonid) {
this.actionreasonid = actionreasonid;
}
public string getservtype() {
return this.servtype;
}
public void setservtype(string servtype) {
this.servtype = servtype;
}
public string getsubservtype() {
return this.subservtype;
}
public void setsubservtype(string subservtype) {
this.subservtype = subservtype;
}
public string getspid() {
return this.spid;
}
public void setspid(string spid) {
this.spid = spid;
}
public string getspservid() {
return this.spservid;
}
public void setspservid(string spservid) {
this.spservid = spservid;
}
public string getaccessmode() {
return this.accessmode;
}
public void setaccessmode(string accessmode) {
this.accessmode = accessmode;
}
public string getfeetype() {
return this.feetype;
}
public void setfeetype(string feetype) {
this.feetype = feetype;
}
}
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
apollo与springboot集成实现动态刷新配置的教程详解
网友评论