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

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Java中的xml

Java中的xml

human123 2015-12-25 20:35:39
package?com.imooc.jdomtest; import?java.io.FileInputStream; import?java.io.FileNotFoundException; import?java.io.IOException; import?java.io.InputStream; import?java.util.ArrayList; import?java.util.List; import?org.jdom2.Attribute; import?org.jdom2.Document; import?org.jdom2.Element; import?org.jdom2.JDOMException; import?org.jdom2.input.SAXBuilder; import?com.imooc.entity.Book; public?class?JDOMTest?{ ????/** ?????*?@param?args ?????*/ ????public?static?void?main(String[]?args)?{ ????????//private?static?ArrayList<Book>?booksList?=new?ArrayList<Book>(); ????????ArrayList<Book>?booksList=new?ArrayList<Book>(); ????????//?進行對book.xml文件的JDOM解析 ????????//?準備工作 ????????//?1.創(chuàng)建一個SAXBuilder對象 ????????SAXBuilder?saxBuilder?=?new?SAXBuilder(); ????????InputStream?in; ????????try?{ ????????????//?2.創(chuàng)建一個輸入流,將xml文件加載到輸入流中 ????????????in?=?new?FileInputStream("src/res/books.xml"); ????????????//?3.通過saxBuilder的build方法,將輸入流加載到saxBuilder中 ????????????Document?document?=?saxBuilder.build(in); ????????????//?4.通過document對象獲取xml文件的根節(jié)點 ????????????Element?rootelement?=?document.getRootElement(); ????????????//?5.獲取根節(jié)點下的子節(jié)點的List集合 ????????????List<Element>?bookList?=?rootelement.getChildren(); ????????????//?繼續(xù)進行解析 ????????????for?(Element?book?:?bookList)?{ ????????????????Book?bookEntity=?new?Book(); ????????????????System.out.println("=========開始解析第" ????????????????????????+?(bookList.indexOf(book)?+?1)?+?"書=========="); ????????????????//?解析book的屬性 ????????????????List<Attribute>?attrList?=?book.getAttributes(); ????????????????//?知道節(jié)點下屬性名稱時,獲取節(jié)點值 ????????????????//?book.getAttributeValue("id"); ????????????????//?遍歷attrList(針對不清楚book節(jié)點下屬性的名字及數(shù)量) ????????????????for?(Attribute?attr?:?attrList)?{ ????????????????????//?獲取屬性名 ????????????????????String?attrName?=?attr.getName(); ????????????????????//?獲取屬性值 ????????????????????String?attrValue?=?attr.getValue(); ????????????????????System.out.println("屬性名:"?+?attrName?+?"------屬性值:" ????????????????????????????+?attrValue); ???????????????????? ????????????????????if?(attrName.equals("id"))?{ ????????????????????????bookEntity.setId(attrValue); ????????????????????} ????????????????} ????????????????//?對book節(jié)點的子節(jié)點的節(jié)點名以及節(jié)點值 ????????????????List<Element>?bookChilds?=?book.getChildren(); ????????????????for?(Element?child?:?bookChilds)?{ ????????????????????System.out.println("節(jié)點名:"?+?child.getName()?+?"----節(jié)點值:" ????????????????????????????+?child.getValue()); ????????????????????if?(child.getName().equals("name"))?{ ????????????????????????bookEntity.setName(child.getValue()); ????????????????????}else?if?(child.getName().equals("author"))?{ ????????????????????????bookEntity.setAuthor(child.getValue()); ????????????????????}else?if?(child.getName().equals("year"))?{ ????????????????????????bookEntity.setYear(child.getValue()); ????????????????????}else?if?(child.getName().equals("price"))?{ ????????????????????????bookEntity.setPrice(child.getValue()); ????????????????????}else?if?(child.getName().equals("language"))?{ ????????????????????????bookEntity.setLanguage(child.getValue()); ????????????????????} ????????????????} ????????????????System.out.println("=========結(jié)束解析第" ????????????????????????+?(bookList.indexOf(book)?+?1)?+?"書=========="); ????????????????/*booksList.add(bookEntity); ????????????????bookEntity=null;*/ ????????????} ????????}?catch?(FileNotFoundException?e)?{ ????????????e.printStackTrace(); ????????}?catch?(JDOMException?e)?{ ????????????e.printStackTrace(); ????????}?catch?(IOException?e)?{ ????????????e.printStackTrace(); ????????} ????} }這里?//private?static?ArrayList<Book>?booksList?=new?ArrayList<Book>(); ????????ArrayList<Book>?booksList=new?ArrayList<Book>();為什么一加上private就報錯
查看完整描述

2 回答

?
產(chǎn)品經(jīng)理不是經(jīng)理

TA貢獻481條經(jīng)驗 獲得超143個贊

private修飾的是成員變量和成員方法的,方法里的局部變量是不能加修飾符的

查看完整回答
反對 回復 2015-12-26
  • 2 回答
  • 0 關(guān)注
  • 1484 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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