第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

為什么解析xml輸出全是null?是讀取節(jié)點(diǎn)屬性方式的問(wèn)題嗎?

為什么解析xml輸出全是null?是讀取節(jié)點(diǎn)屬性方式的問(wèn)題嗎?

qq_飛翔的勇氣_0 2018-08-21 08:44:47
代碼:Dom4JReaderUtils類package com.xml;import java.io.File;import org.dom4j.Document;import org.dom4j.DocumentException;import org.dom4j.io.SAXReader;public class Dom4JReaderUtils {? private static final String RESOURCE;? static{ ??RESOURCE=Dom4JReaderUtils.class.getClassLoader().getResource("peopleList.xml").getPath();? }? public static Document getDocument(){Document document=null;SAXReader reader=new SAXReader();try{document=reader.read(new File(RESOURCE));}catch(DocumentException e){e.printStackTrace();}return document; ?? }}people實(shí)體類package com.xml;public class People {? ?private String position;? ?private String unid;? ?private String noteid;? ?private String sibings;? ?private String name;? ?private String FullName;? ?private String dept;? ?private String role;? ?private String duty;? ?private String wkgp;public String getPosition() {return position;}public void setPosition(String position) {this.position = position;}public String getUnid() {return unid;}public void setUnid(String unid) {this.unid = unid;}public String getNoteid() {return noteid;}public void setNoteid(String noteid) {this.noteid = noteid;}public String getSibings() {return sibings;}public void setSibings(String sibings) {this.sibings = sibings;}public String getName() {return name;}public void setName(String name) {this.name = name;}public String getFullName() {return FullName;}public void setFullName(String fullName) {FullName = fullName;}public String getDept() {return dept;}public void setDept(String dept) {this.dept = dept;}public String getRole() {return role;}public void setRole(String role) {this.role = role;}public String getDuty() {return duty;}public void setDuty(String duty) {this.duty = duty;}public String getWkgp() {return wkgp;}public void setWkgp(String wkgp) {this.wkgp = wkgp;}@Override ??public String toString(){??return "people[position="+position+",unid="+unid+",noteid="+noteid+",sibings="+sibings+?",name="+name+",FullName="+FullName+",dept="+dept+",role="+role+",duty="+duty+"]"+"\n";}}測(cè)試類package com.xml;import java.util.ArrayList;import java.util.Iterator;import java.util.List;import org.dom4j.Attribute;import org.dom4j.Document;import org.dom4j.Element;import org.dom4j.io.SAXReader;public class Test {? ? ?? public static List<People> getPeopleListFromXml(Document document){? List<People> peopleList=new ArrayList<People>();? Element root=document.getRootElement();? Iterator<Element> peopleIterator=root.elementIterator();? while(peopleIterator.hasNext()){? Element element=peopleIterator.next();? People people=new People();? people.setName(element.elementText("name"));?? people.setFullName(element.elementText("FullName"));? people.setDept(element.elementText("dept"));? people.setRole(element.elementText("role"));? people.setDuty(element.elementText("duty"));? people.setUnid(element.elementText("unid"));? ? ? ? ? Iterator<Attribute>peopleAttr=element.attributeIterator();? ? ? ? ? while(peopleAttr.hasNext()){? ? ? ? ? Attribute attribute=peopleAttr.next();? ? ? ? ? String attributeName=attribute.getName();// ? ? ? ? ? String attributeName1=attribute.getName();? ? ? ? ? if(attributeName.equals("position")){? ? ? ? ? people.setPosition(attribute.getValue());? ? ? ? ? }else{? ? ? ? ? people.setUnid(attribute.getValue());? ? ? ? ? }? ? ? ? ? }? ? ? ? ? peopleList.add(people);? }System.out.println(root.getName());return peopleList; ??? }/*** @param args*/public static void main(String[] args) {? ? ? ?Document document=Dom4JReaderUtils.getDocument();? ? ? ?List<People>peopleList=getPeopleListFromXml(document);? ? ? ?System.out.println(peopleList);? ? ? ?}}xml:<viewentry position="2" unid="A" noteid="3" siblings="14"><entrydata columnnumber="1" name="name"><text>王五</text></entrydata><entrydata columnnumber="2" name="FullName"><text>王五/華夏/ZJCZ</text></entrydata><entrydata columnnumber="3" name="dept"><text>辦公室(科研處)</text></entrydata><entrydata columnnumber="4" name="role"><text>辦公室秘書崗</text></entrydata><entrydata columnnumber="5" name="duty"><text>其他</text></entrydata><entrydata columnnumber="6" name="wkgp"><text></text></entrydata></viewentry>
查看完整描述

目前暫無(wú)任何回答

  • 0 回答
  • 0 關(guān)注
  • 1294 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)