加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

解析 XML

发布时间:2020-12-16 05:56:58 所属栏目:百科 来源:网络整理
导读://球员排行榜xml public void playerTop(){ DTOPTAPLAYTOP top = new DTOPTAPLAYTOP(); //积分榜 SAXReader saxReader = new SAXReader(); Document document = null; try { document = saxReader.read(new File("C://Users//Mao//Downloads//足球数据接口//x
//球员排行榜xml public void playerTop(){ DTOPTAPLAYTOP top = new DTOPTAPLAYTOP(); //积分榜 SAXReader saxReader = new SAXReader(); Document document = null; try { document = saxReader.read(new File("C://Users//Mao//Downloads//足球数据接口//x42-133-2013-playertop.xml")); } catch (DocumentException e) { e.printStackTrace(); } Element roots = document.getRootElement();//得到根元素 String season = roots.element("DataDocument").attributeValue("Season"); String CompName = roots.element("DataDocument").attributeValue("CompName"); String CompId = roots.element("DataDocument").attributeValue("CompId"); top.setSeason(season); top.setCompname(CompName); top.setCompid(Integer.parseInt(CompId)); for(Iterator i = roots.element("DataDocument").elementIterator();i.hasNext();){ Element team = (Element) i.next(); String type = team.getName(); for(Iterator j = team.elementIterator("Ranking");j.hasNext();){ Element rd = (Element) j.next(); top.setPlayid(Integer.parseInt(rd.attributeValue("PlayId"))); top.setTeamname(rd.attributeValue("TeamName")); top.setTeamid(Integer.parseInt(rd.attributeValue("TeamId"))); top.setType(type); //Goal节点 top.setHeader(rd.attributeValue("Header") == null ? 0 : Integer.parseInt(rd.attributeValue("Header"))); top.setFreekick(rd.attributeValue("Freekick") == null ? 0 : Integer.parseInt(rd.attributeValue("Freekick"))); top.setOwn(rd.attributeValue("Own") == null ? 0 : Integer.parseInt(rd.attributeValue("Own"))); top.setPenalty(rd.attributeValue("Penalty") == null ? 0 : Integer.parseInt(rd.attributeValue("Penalty"))); top.setGoal(rd.attributeValue("Goal") == null ? 0 : Integer.parseInt(rd.attributeValue("Goal"))); top.setGoaltotal(rd.attributeValue("GoalTotal") == null ? 0 : Integer.parseInt(rd.attributeValue("GoalTotal"))); top.setPlayname(rd.attributeValue("PlayName") == null ? null : rd.attributeValue("PlayName")); top.setOptateamid(rd.attributeValue("OptaTeamId") == null ? null : rd.attributeValue("OptaTeamId")); //Card节点 top.setYellow2(rd.attributeValue("Yellow2") == null ? 0 : Integer.parseInt(rd.attributeValue("Yellow2"))); top.setYellow(rd.attributeValue("Yellow") == null ? 0 : Integer.parseInt(rd.attributeValue("Yellow"))); top.setRed(rd.attributeValue("Red") == null ? 0 : Integer.parseInt(rd.attributeValue("Red"))); //Shot节点 top.setOptaplayid(rd.attributeValue("OptaPlayId") == null ? null : rd.attributeValue("OptaPlayId")); top.setOptateamid(rd.attributeValue("OptaTeamId") == null ? null : rd.attributeValue("OptaTeamId")); top.setShotother(rd.attributeValue("ShotOther") == null ? 0 : Integer.parseInt(rd.attributeValue("ShotOther"))); top.setShotheader(rd.attributeValue("ShotHeader") == null ? 0 : Integer.parseInt(rd.attributeValue("ShotHeader"))); top.setShotright(rd.attributeValue("ShotRight") == null ? 0 : Integer.parseInt(rd.attributeValue("ShotRight"))); top.setShotleft(rd.attributeValue("ShotLeft") == null ? 0 : Integer.parseInt(rd.attributeValue("ShotLeft"))); top.setShottotal(rd.attributeValue("ShotTotal") == null ? 0 : Integer.parseInt(rd.attributeValue("ShotTotal"))); //Assist节点 top.setOptaplayid(rd.attributeValue("OptaPlayId") == null ? null : rd.attributeValue("OptaPlayId")); top.setOptateamid(rd.attributeValue("OptaTeamId") == null ? null : rd.attributeValue("OptaTeamId")); top.setAssisttotal(rd.attributeValue("AssistTotal") == null ? 0 : Integer.parseInt(rd.attributeValue("AssistTotal"))); //Pass节点 top.setOptaplayid(rd.attributeValue("OptaPlayId") == null ? null : rd.attributeValue("OptaPlayId")); top.setOptateamid(rd.attributeValue("OptaTeamId") == null ? null : rd.attributeValue("OptaTeamId")); top.setPasstotal(rd.attributeValue("PassTotal") == null ? 0 : Integer.parseInt(rd.attributeValue("PassTotal"))); //keypass节点 top.setOptaplayid(rd.attributeValue("OptaPlayId") == null ? null : rd.attributeValue("OptaPlayId")); top.setOptateamid(rd.attributeValue("OptaTeamId") == null ? null : rd.attributeValue("OptaTeamId")); top.setKeypasstotal(rd.attributeValue("KeypassTotal") == null ? 0 : Integer.parseInt(rd.attributeValue("KeypassTotal"))); //cross top.setCrosstotal(rd.attributeValue("CrossTotal") == null ? 0 : Integer.parseInt(rd.attributeValue("CrossTotal"))); top.setOptaplayid(rd.attributeValue("OptaPlayId") == null ? null : rd.attributeValue("OptaPlayId")); top.setOptateamid(rd.attributeValue("OptaTeamId") == null ? null : rd.attributeValue("OptaTeamId")); //save top.setOptaplayid(rd.attributeValue("OptaPlayId") == null ? null : rd.attributeValue("OptaPlayId")); top.setOptateamid(rd.attributeValue("OptaTeamId") == null ? null : rd.attributeValue("OptaTeamId")); top.setSavetotal(rd.attributeValue("SaveTotal") == null ? 0 : Integer.parseInt(rd.attributeValue("SaveTotal"))); //tackle top.setTackletotal(rd.attributeValue("TackleTotal") == null ? 0 : Integer.parseInt(rd.attributeValue("TackleTotal"))); top.setOptaplayid(rd.attributeValue("OptaPlayId") == null ? null : rd.attributeValue("OptaPlayId")); top.setOptateamid(rd.attributeValue("OptaTeamId") == null ? null : rd.attributeValue("OptaTeamId")); //foul top.setFoultotal(rd.attributeValue("FoulTotal") == null ? 0 : Integer.parseInt(rd.attributeValue("FoulTotal"))); top.setOptaplayid(rd.attributeValue("OptaPlayId") == null ? null : rd.attributeValue("OptaPlayId")); top.setOptateamid(rd.attributeValue("OptaTeamId") == null ? null : rd.attributeValue("OptaTeamId")); //fouled top.setFouledtotal(rd.attributeValue("FouledTotal") == null ? 0 : Integer.parseInt(rd.attributeValue("FouledTotal"))); top.setOptaplayid(rd.attributeValue("OptaPlayId") == null ? null : rd.attributeValue("OptaPlayId")); top.setOptateamid(rd.attributeValue("OptaTeamId") == null ? null : rd.attributeValue("OptaTeamId")); //clearence top.setClearancetotal(rd.attributeValue("ClearanceTotal") == null ? 0 : Integer.parseInt(rd.attributeValue("ClearanceTotal"))); top.setOptaplayid(rd.attributeValue("OptaPlayId") == null ? null : rd.attributeValue("OptaPlayId")); top.setOptateamid(rd.attributeValue("OptaTeamId") == null ? null : rd.attributeValue("OptaTeamId")); //minutes top.setOptaplayid(rd.attributeValue("OptaPlayId") == null ? null : rd.attributeValue("OptaPlayId")); top.setOptateamid(rd.attributeValue("OptaTeamId") == null ? null : rd.attributeValue("OptaTeamId")); top.setMinutestotal(rd.attributeValue("MinutesTotal") == null ? 0 : Integer.parseInt(rd.attributeValue("MinutesTotal"))); //相同teamId不再插入 DTOPTAPLAYTOP dtOptaPlaytop = dtOptaPlayTopService.findTeamById(Integer.parseInt(rd.attributeValue("PlayId")),type); if(dtOptaPlaytop == null){ dtOptaPlayTopService.insert(top); } } } } //阵容 public void squads(){ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); DTOPTASQUADS squads = new DTOPTASQUADS(); SAXReader saxReader = new SAXReader(); Document document = null; try { document = saxReader.read(new File("C://Users//Mao//Downloads//足球数据接口//x80-133-2013-squads.xml")); } catch (DocumentException e) { e.printStackTrace(); } Element roots = document.getRootElement();//得到根元素 for(Iterator i = roots.elementIterator();i.hasNext();){ Element team = (Element) i.next(); String teamId = team.attributeValue("TeamId"); if(team.getName().equals("Team")){ for(Iterator j = team.elementIterator();j.hasNext();){ Element rd = (Element) j.next(); if(rd.getName().equals("TeamInfo")){ squads.setTeamid(Integer.parseInt(teamId)); squads.setTeamname(rd.elementText("Name")); } if(rd.getName().equals("TeamOfficial")){ squads.setCoachid(rd.attributeValue("PlayId") == null ? 0 : Integer.parseInt(rd.attributeValue("PlayId"))); squads.setCoachcnname(rd.elementText("Name")); squads.setCoachenname(rd.elementText("EnglishName")); if(rd.elementText("BirthDate") != null){ try { squads.setCoachbirthday(sdf.parse(rd.elementText("BirthDate"))); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } if(rd.getName().equals("Squads")){ for(Iterator k = rd.elementIterator();k.hasNext();){ Element player = (Element) k.next(); squads.setPlayid(player.attributeValue("PlayId") == null ? 0 : Integer.parseInt(player.attributeValue("PlayId"))); squads.setName(player.elementText("Name")); squads.setEnname(player.elementText("EnglishName")); squads.setWeight(player.elementText("Weight") == null ? 0 : Integer.parseInt(player.elementText("Weight"))); squads.setHeight(player.elementText("Height") == null ? 0 : Integer.parseInt(player.elementText("Height"))); if(player.elementText("BirthDate") != null){ try { squads.setBirthday(sdf.parse(player.elementText("BirthDate"))); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } } squads.setCareervalue(player.elementText("CareerValue") == null ? 0 : Double.valueOf(player.elementText("CareerValue"))); if(player.element("Position") != null){ squads.setPositionid(player.element("Position").attributeValue("PositionId") == null ? 0 : Integer.parseInt(player.element("Position").attributeValue("PositionId"))); } squads.setPosition(player.elementText("Position")); squads.setCounid(player.element("Country").attributeValue("CounId") == null ? 0 : Integer.parseInt(player.element("Country").attributeValue("CounId"))); squads.setCountry(player.elementText("Country")); squads.setCityid(player.element("City").attributeValue("City") == null ? 0 : Integer.parseInt(player.element("City").attributeValue("City"))); squads.setCity(player.elementText("City")); squads.setLogo(player.elementText("Logo")); squads.setJerseynum(player.elementText("JerseyNum") == null ? 0 : Integer.parseInt(player.elementText("JerseyNum"))); squads.setPreferredfoot(player.elementText("PreferredFoot")); //相同teamId不再插入 DTOPTASQUADS dtOptaSquads = dtOptaSquadsService.findSquadsById(Integer.parseInt(teamId)); if(dtOptaSquads == null){ dtOptaSquadsService.insert(squads); } } } } } } } //转会 public void transfer(){ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); DTOPTATRANSFER transfer = new DTOPTATRANSFER(); SAXReader saxReader = new SAXReader(); Document document = null; try { document = saxReader.read(new File("C://Users//Mao//Downloads//足球数据接口//x82-133-2013-transfer.xml")); } catch (DocumentException e) { e.printStackTrace(); } Element roots = document.getRootElement();//得到根元素 String season = roots.element("DataDocument").attributeValue("Season"); String CompName = roots.element("DataDocument").attributeValue("CompName"); String CompId = roots.element("DataDocument").attributeValue("CompId"); transfer.setSeason(season); transfer.setCompname(CompName); transfer.setCompid(Integer.parseInt(CompId)); for(Iterator i = roots.element("DataDocument").elementIterator();i.hasNext();){ Element team = (Element) i.next(); String teamId = team.attributeValue("TeamId"); transfer.setTeamid(Integer.parseInt(teamId)); transfer.setTeamname(team.attributeValue("TeamName")); transfer.setLogo(team.attributeValue("Logo")); for(Iterator j = team.elementIterator();j.hasNext();){ Element fer = (Element) j.next(); transfer.setType(fer.getName()); for(Iterator k = fer.elementIterator();k.hasNext();){ Element rd = (Element) k.next(); System.out.println(rd.attributeValue("PlayName")); transfer.setTransferteam(rd.attributeValue("TeamName")); transfer.setTransferteamid(Integer.parseInt(rd.attributeValue("TeamId"))); transfer.setTransferfee(rd.attributeValue("TransferFee") == null ? 0 : Integer.parseInt(rd.attributeValue("TransferFee"))); transfer.setTranskindname(rd.attributeValue("TranskindName")); try { transfer.setTransferdate(sdf.parse(rd.attributeValue("TransferDate"))); } catch (ParseException e) { e.printStackTrace(); } transfer.setTransferplayname(rd.attributeValue("PlayName")); transfer.setTransferplayid(Integer.parseInt(rd.attributeValue("PlayId"))); DTOPTATRANSFER trans = dtOptaTransferService.findTransferById(Integer.parseInt(rd.attributeValue("PlayId"))); if(trans == null){ dtOptaTransferService.insert(transfer); } } } } }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读