XML解析小记之防止数据过长被截断
来源:互联网 发布:广东高考难度 知乎 编辑:程序博客网 时间:2024/05/21 09:56
public class AppWebSaxXml extends DefaultHandler {
private StringBuilder sb = new StringBuilder();
private AppWebEntity appEntity;
private List<AppWebEntity> appEntitys;
private String preTag;
@Override
public void startDocument() throws SAXException {
appEntitys = new ArrayList<AppWebEntity>();
}
@Override
public void characters(char[] ch, int start, int length)
throws SAXException {
//(2)不管在startElement到endElement的过程中,执行了多少次characters, 都会将内容添加到StringBuilder中,不会丢失内容
sb.append(ch, start, length);
}
@Override
public void startElement(String uri, String localName, String name,
Attributes attr) throws SAXException {
//(3) 开始收集新的标签的数据时,先清空历史数据
sb.setLength(0);
if ("Message".equals(name)) {
appEntity=new AppWebEntity();
}
preTag=name;
}
@Override
public void endElement(String uri, String localName, String name)
throws SAXException {
if(appEntity!=null){
String data = sb.toString();
if ("IMSI".equals(preTag)) {
appEntity.setPhoneInfo_IMSI(data);
}
if ("MEID".equals(preTag)) {
appEntity.setPhoneInfo_MEID(data);
}
if ("PhoneType".equals(preTag)) {
appEntity.setPhoneInfo_PhoneType(data);
}
if ("OSVersion".equals(preTag)) {
appEntity.setPhoneInfo_OSVersion(data);
}
if ("BaseBand".equals(preTag)) {
appEntity.setPhoneInfo_BaseBand(data);
}
if ("Kernel".equals(preTag)) {
appEntity.setPhoneInfo_Kernel(data);
}
if ("InnerVersion".equals(preTag)) {
appEntity.setPhoneInfo_InnerVersion(data);
}
if ("RamUsage".equals(preTag)) {
appEntity.setPhoneInfo_RamUsage(data);
}
if ("CpuUsage".equals(preTag)) {
appEntity.setPhoneInfo_CpuUsage(data);
}
if ("Longitude".equals(preTag)) {
appEntity.setPositionInfo_Longitude(data);
}
if ("Latitude".equals(preTag)) {
appEntity.setPositionInfo_Latitude(data);
}
if ("LocationDesc".equals(preTag)) {
appEntity.setPositionInfo_LocationDesc(data);
}
if ("Province".equals(preTag)) {
appEntity.setPositionInfo_Province(data);
}
if ("City".equals(preTag)) {
appEntity.setPositionInfo_City(data);
}
if ("NetType".equals(preTag)) {
appEntity.setNetInfo_NetType(data);
}
if ("APN".equals(preTag)) {
appEntity.setNetInfo_APN(data);
}
if ("CdmaSid".equals(preTag)) {
appEntity.setNetInfo_CdmaSid(data);
}
if ("CdmaNid".equals(preTag)) {
appEntity.setNetInfo_CdmaNid(data);
}
if ("CdmaBsid".equals(preTag)) {
appEntity.setNetInfo_CdmaBsid(data);
}
if ("CdmadBm".equals(preTag)) {
appEntity.setNetInfo_CdmadBm(data);
}
if ("LteCi".equals(preTag)) {
appEntity.setNetInfo_LteCi(data);
}
if ("LtePci".equals(preTag)) {
appEntity.setNetInfo_LtePci(data);
}
if ("LteTac".equals(preTag)) {
appEntity.setNetInfo_LteTac(data);
}
if ("LteRsrp".equals(preTag)) {
appEntity.setNetInfo_LteRsrp(data);
}
if ("LteSinr".equals(preTag)) {
appEntity.setNetInfo_LteSinr(data);
}
if ("InnerIP".equals(preTag)) {
appEntity.setNetInfo_InnerIP(data);
}
if ("OuterIP".equals(preTag)) {
appEntity.setNetInfo_OuterIP(data);
}
if ("WebsiteName".equals(preTag)) {
appEntity.setTestResult_WebsiteName(data);
}
if ("PageURL".equals(preTag)) {
appEntity.setTestResult_PageURL(data);
}
if ("PageIP".equals(preTag)) {
appEntity.setTestResult_PageIP(data);
}
if ("PageSurfTime".equals(preTag)) {
appEntity.setTestResult_PageSurfTime(data);
}
if ("FirstByteDelay".equals(preTag)) {
appEntity.setTestResult_FirstByteDelay(data);
}
if ("PageOpenDelay".equals(preTag)) {
appEntity.setTestResult_PageOpenDelay(data);
}
if ("RRCSetupDelay".equals(preTag)) {
appEntity.setTestResult_RRCSetupDelay(data);
}
if ("DnsDelay".equals(preTag)) {
appEntity.setTestResult_DnsDelay(data);
}
if ("ConnDelay".equals(preTag)) {
appEntity.setTestResult_ConnDelay(data);
}
if ("ReqDelay".equals(preTag)) {
appEntity.setTestResult_ReqDelay(data);
}
if ("ResDelay".equals(preTag)) {
appEntity.setTestResult_ResDelay(data);
}
if ("TCLASS".equals(preTag)) {
appEntity.setTestResult_TCLASS(data);
}
if ("Success".equals(preTag)) {
appEntity.setTestResult_Success(data);
}
}
if ("Message".equals(name)) {
appEntitys.add(appEntity);
appEntity=null;
}
preTag = null;
}
public List<AppWebEntity> getList() {
// TODO Auto-generated method stub
return appEntitys;
}
}
private StringBuilder sb = new StringBuilder();
private AppWebEntity appEntity;
private List<AppWebEntity> appEntitys;
private String preTag;
@Override
public void startDocument() throws SAXException {
appEntitys = new ArrayList<AppWebEntity>();
}
@Override
public void characters(char[] ch, int start, int length)
throws SAXException {
//(2)不管在startElement到endElement的过程中,执行了多少次characters, 都会将内容添加到StringBuilder中,不会丢失内容
sb.append(ch, start, length);
}
@Override
public void startElement(String uri, String localName, String name,
Attributes attr) throws SAXException {
//(3) 开始收集新的标签的数据时,先清空历史数据
sb.setLength(0);
if ("Message".equals(name)) {
appEntity=new AppWebEntity();
}
preTag=name;
}
@Override
public void endElement(String uri, String localName, String name)
throws SAXException {
if(appEntity!=null){
String data = sb.toString();
if ("IMSI".equals(preTag)) {
appEntity.setPhoneInfo_IMSI(data);
}
if ("MEID".equals(preTag)) {
appEntity.setPhoneInfo_MEID(data);
}
if ("PhoneType".equals(preTag)) {
appEntity.setPhoneInfo_PhoneType(data);
}
if ("OSVersion".equals(preTag)) {
appEntity.setPhoneInfo_OSVersion(data);
}
if ("BaseBand".equals(preTag)) {
appEntity.setPhoneInfo_BaseBand(data);
}
if ("Kernel".equals(preTag)) {
appEntity.setPhoneInfo_Kernel(data);
}
if ("InnerVersion".equals(preTag)) {
appEntity.setPhoneInfo_InnerVersion(data);
}
if ("RamUsage".equals(preTag)) {
appEntity.setPhoneInfo_RamUsage(data);
}
if ("CpuUsage".equals(preTag)) {
appEntity.setPhoneInfo_CpuUsage(data);
}
if ("Longitude".equals(preTag)) {
appEntity.setPositionInfo_Longitude(data);
}
if ("Latitude".equals(preTag)) {
appEntity.setPositionInfo_Latitude(data);
}
if ("LocationDesc".equals(preTag)) {
appEntity.setPositionInfo_LocationDesc(data);
}
if ("Province".equals(preTag)) {
appEntity.setPositionInfo_Province(data);
}
if ("City".equals(preTag)) {
appEntity.setPositionInfo_City(data);
}
if ("NetType".equals(preTag)) {
appEntity.setNetInfo_NetType(data);
}
if ("APN".equals(preTag)) {
appEntity.setNetInfo_APN(data);
}
if ("CdmaSid".equals(preTag)) {
appEntity.setNetInfo_CdmaSid(data);
}
if ("CdmaNid".equals(preTag)) {
appEntity.setNetInfo_CdmaNid(data);
}
if ("CdmaBsid".equals(preTag)) {
appEntity.setNetInfo_CdmaBsid(data);
}
if ("CdmadBm".equals(preTag)) {
appEntity.setNetInfo_CdmadBm(data);
}
if ("LteCi".equals(preTag)) {
appEntity.setNetInfo_LteCi(data);
}
if ("LtePci".equals(preTag)) {
appEntity.setNetInfo_LtePci(data);
}
if ("LteTac".equals(preTag)) {
appEntity.setNetInfo_LteTac(data);
}
if ("LteRsrp".equals(preTag)) {
appEntity.setNetInfo_LteRsrp(data);
}
if ("LteSinr".equals(preTag)) {
appEntity.setNetInfo_LteSinr(data);
}
if ("InnerIP".equals(preTag)) {
appEntity.setNetInfo_InnerIP(data);
}
if ("OuterIP".equals(preTag)) {
appEntity.setNetInfo_OuterIP(data);
}
if ("WebsiteName".equals(preTag)) {
appEntity.setTestResult_WebsiteName(data);
}
if ("PageURL".equals(preTag)) {
appEntity.setTestResult_PageURL(data);
}
if ("PageIP".equals(preTag)) {
appEntity.setTestResult_PageIP(data);
}
if ("PageSurfTime".equals(preTag)) {
appEntity.setTestResult_PageSurfTime(data);
}
if ("FirstByteDelay".equals(preTag)) {
appEntity.setTestResult_FirstByteDelay(data);
}
if ("PageOpenDelay".equals(preTag)) {
appEntity.setTestResult_PageOpenDelay(data);
}
if ("RRCSetupDelay".equals(preTag)) {
appEntity.setTestResult_RRCSetupDelay(data);
}
if ("DnsDelay".equals(preTag)) {
appEntity.setTestResult_DnsDelay(data);
}
if ("ConnDelay".equals(preTag)) {
appEntity.setTestResult_ConnDelay(data);
}
if ("ReqDelay".equals(preTag)) {
appEntity.setTestResult_ReqDelay(data);
}
if ("ResDelay".equals(preTag)) {
appEntity.setTestResult_ResDelay(data);
}
if ("TCLASS".equals(preTag)) {
appEntity.setTestResult_TCLASS(data);
}
if ("Success".equals(preTag)) {
appEntity.setTestResult_Success(data);
}
}
if ("Message".equals(name)) {
appEntitys.add(appEntity);
appEntity=null;
}
preTag = null;
}
public List<AppWebEntity> getList() {
// TODO Auto-generated method stub
return appEntitys;
}
}
1 0
- XML解析小记之防止数据过长被截断
- SAX 解析 XML 字符串截断 数据不完整 解决办法
- 返回xml或json过长时被nginx截断的解决办法
- jsp过长的数据,截断在后面补以....显示
- 数据解析之XML
- Android数据解析之XML数据解析
- Cast类型转换字符过长可能被截断
- textView中文本过长被截断的解决方案
- Android 4.0 Notification内容过长被截断,无法完整显示
- PHP返回内容过长时被nginx截断的解决办法
- iOS之数据解析之XML解析
- iOS之数据解析之XML解析
- PHP分割英文字符串,防止被截断
- PHP分割英文字符串,防止被截断
- Android代码小记之Xml解析工具类
- Android 数据解析之 Xml
- ASP过长标题如何截断
- xml之数据解析及schema解析
- comet4j的使用
- YII2 日志
- 【leetcode】2. Add Two Numbers
- 安卓自定义view总结1
- Window系统下CMD命令大全(二)
- XML解析小记之防止数据过长被截断
- redis中数据持久化(四)
- HDU 4499 Cannon
- JavaSE学习笔记_19:Java-GUI
- 《Head First设计模式》 - 观察者模式
- "多米诺骨牌"问题的动态规划算法
- Java NIO - CountDownLatch
- VC实现当前程序退出后重启
- BZOJ 4010: [HNOI2015]菜肴制作