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

為了賬號安全,請及時綁定郵箱和手機立即綁定

為什么解析xml輸出全是null??

代碼:

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實體類

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";

}

}

測試類

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>


https://img1.sycdn.imooc.com//5b6a4f1200016d6813280074.jpg

正在回答

0 回答

舉報

0/150
提交
取消
Java眼中的XML---文件讀取
  • 參與學(xué)習(xí)       83200    人
  • 解答問題       444    個

通過Java認識并且創(chuàng)造XML文件,如何應(yīng)用 Java“解析 XML

進入課程

為什么解析xml輸出全是null??

我要回答 關(guān)注問題
微信客服

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

幫助反饋 APP下載

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

公眾號

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