亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb

首頁 > 學院 > 開發設計 > 正文

你所應該知道的Dom4J

2019-11-14 22:56:13
字體:
來源:轉載
供稿:網友
你所應該知道的Dom4J

創建解析器:

SAXReader reader = new SAXReader();

利用解析器讀入xml文檔: Document document =reader.read(new File("input.xml"));

獲取文檔的根節點:

Element root =document.getRootElement();

接口繼承結構:

Node ---

Branch

--Document

--Element

----

Attribute

Node接口

String

asXML() asXMLreturns the textual XML rePResentation of this node.

將一個節點轉換為字符串

String

getName() getNamereturns the name of this node.

獲取節點的名稱,如果是元素則獲取到元素名,如果是屬性獲取到屬性名

short

getNodeType() Returns the code according to the type of node.

獲取節點類型,在Node接口上定義了一些靜態short類型的常量用來表示各種類型

Element

getParent() getParentreturns the parent Element if this node supports the parent relationship or null if it is the root element or does not support the parent relationship.

獲取父節點,如果是根元素調用則返回null,如果是其他元素調用則返回父元素,如果是屬性調用則返回屬性所依附的元素。

String

getText() Returns the text of this node.

返回節點文本,如果是元素則返回標簽體,如果是屬性則返回屬性值

List

selectNodes(String xpathExpression) selectNodesevaluates an XPath expression and returns the result as a List of Node instances or String instances depending on the XPath expression.

利用xpath表達式,選擇節點

void

setName(String name) Sets the text data of this node or this method will throw an UnsupportedOperationException if it is read-only.

設置節點的名稱,元素可以更改名稱,屬性則不可以,會拋出UnsupportedOperationException 異常

void

setText(String text) Sets the text data of this node or this method will throw an UnsupportedOperationException if it is read-only.

設置節點內容,如果是元素則設置標簽體,如果是屬性則設置屬性的值

void

write(Writer writer) writewrites this node as the default XML notation for this node.

將節點寫出到一個輸出流中,元素、屬性均支持

Branch接口(實現了Node接口)

void

add(Element element) Adds the given Element to this branch.

增加一個子節點

Element

addElement(QName qname) Adds a new Element node with the given QNameto this branch and returns a reference to the new node.

增加一個給定名字的子節點,并且返回這個新創建的節點的引用

int

indexOf(Node node) Returns the index of the given node if it is a child node of this branch or -1 if the given node is not a child node.

獲取給定節點在所有直接點中的位置號,如果該節點不是此分支的子節點,則返回-1

boolean

remove(Element element) Removes the given Element if the node is an immediate child of this branch.

刪除給定子元素,返回布爾值表明是否刪除成功。

Element接口(實現了Branch, Node接口)

void

add(Attribute attribute) Adds the given Attribute to this element.

增加一個屬性

Element

addAttribute(QName qName, String value) Adds the attribute value of the given fully qualified name.

為元素增加屬性,用給定的屬性名和屬性值,并返回該元素

Element

addAttribute(String name, String value) Adds the attribute value of the given local name.

為元素增加屬性

Attribute

attribute(int index) Returns the attribute at the specified indexGets the

獲取指定位置的屬性

Attribute

attribute(QName qName) DOCUMENT ME!

獲取指定名稱的屬性

Iterator

attributeIterator() DOCUMENT ME!

獲取屬性迭代器

List

attributes() Returns the Attributeinstances this element contains as a backed Listso that the attributes may be modified directly using the Listinterface.

獲取該元素的所有屬性,以一個list返回

String

attributeValue(QName qName) This returns the attribute value for the attribute with the given fully qualified name or null if there is no such attribute or the empty string if the attribute value is empty.

獲取指定名稱屬性的值,如果不存在該屬性返回null,如果存在該屬性但是屬性值為空,則返回空字符串

Element

element(QName qName) Returns the first element for the given fully qualified name.

獲取指定名稱的子元素,如果有多個該名稱的子元素,則返回第一個

Element

element(String name) Returns the first element for the given fully qualified name.

獲取指定名稱的子元素,如果有多個該名稱的子元素,則返回第一個

Iterator

elementIterator() Returns an iterator over all this elements child elements.

獲取子元素迭代器

Iterator

elementIterator(QName qName) Returns an iterator over the elements contained in this element which match the given fully qualified name.

獲取指定名稱的子元素的迭代器

List

elements() Returns the elements contained in this element.

獲取所有子元素,并用一個list返回

List

elements(QName qName) Returns the elements contained in this element with the given fully qualified name.

獲取所有指定名稱的子元素,并用一個list返回

String

getText() Returns the text value of this element without recursing through child elements.

獲取元素標簽體

boolean

remove(Attribute attribute) Removes the given Attribute from this element.

移除元素上的屬性

void

setAttributes(List attributes) Sets the attributes that this element contains

將list中的所有屬性設置到該元素上

Attribute接口(實現了Node接口)

QName

getQName() Returns the QName of this attribute which represents the local name, the qualified name and the Namespace.

獲取屬性名稱

String

getValue() Returns the value of the attribute.

獲取屬性的值

void

setValue(String value) Sets the value of this attribute or this method will throw an UnsupportedOperationException if it is read-only.

設置屬性的值

DocumentHelper

static Attribute

createAttribute(Element owner, QName qname, String value)

創建一個Attribute

static Document

createDocument()

創建一個Document

static Document

createDocument(Element rootElement)

以給定元素作為根元素創建Document

static Element

createElement(QName qname)

以給定名稱創建一個Element

static Document

parseText(String text) parseTextparses the given text as an XML document and returns the newly created Document.

將一段字符串轉化為Document

將節點寫出到XML文件中去

方法1:

調用Node提供的write(Writerwriter) 方法,使用默認方式將節點輸出到流中:

node.write(newFileWriter("book.xml"));

亂碼問題:

Dom4j在將文檔載入內存時使用的是文檔聲明中encoding屬性聲明的編碼集進行編碼, 如果在此時使用writer輸出時writer使用的內部編碼集與encoding不同則會有亂碼問題。

FileWriter默認使用操作系統本地碼表即gb2312編碼,并且無法更改。

此時可以使用OutputStreamWriter(FileOutputStream("filePath"),"utf-8");的方式自己封裝 一個指定碼表的Writer使用,從而解決亂碼問題。

方式2:

利用XMLWriter寫出Node: XMLWriter writer = new XMLWriter(new FileWriter("output.xml")); writer.write(node); writer.close();

亂碼問題:

(1)使用這種方式輸出時,XMLWriter首先會將內存中的docuemnt翻譯成UTF-8 格式的document,在進行輸出,這時有可能出現亂碼問題。

可以使用OutputFormat 指定XMLWriter轉換的編碼為其他編碼。

OutputFormat format =OutputFormat.createPrettyPrint();

format.setEncoding("GBK"); XMLWriterwriter = new XMLWriter(new FileWriter("output.xml"),format);

(2)Writer使用的編碼集與文檔載入內存時使用的編碼集不同導致亂碼,使用字節流 或自己封裝指定編碼的字符流即可(參照方法1)。


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb
欧美专区国产专区| 久久久999精品| 中文字幕亚洲一区二区三区五十路| 亚洲自拍另类欧美丝袜| 国产91在线播放| 国产视频亚洲视频| 国产午夜精品全部视频在线播放| 欧美成aaa人片免费看| 最新国产精品拍自在线播放| 国产精品美女主播在线观看纯欲| 国产精品久久网| 亚洲国产一区二区三区四区| 久久国产精品视频| 4p变态网欧美系列| 国产精品电影在线观看| 国语自产精品视频在线看抢先版图片| 性欧美办公室18xxxxhd| 一区二区三欧美| 国产z一区二区三区| 黄网动漫久久久| 亚洲欧洲日产国产网站| 亚洲成人精品av| 国产福利视频一区| 亚洲香蕉av在线一区二区三区| 国产精品h片在线播放| 91av视频导航| 国内精品久久影院| 午夜精品一区二区三区av| 日韩av色在线| 日本精品免费观看| www亚洲精品| 日韩中文在线不卡| 精品国产一区二区三区久久狼5月| 国产精品国产福利国产秒拍| 国产精品久久久久久久久久久久| 日韩视频一区在线| 国产成人精品日本亚洲| 日本成人激情视频| 国产精品成人av性教育| 欧美精品在线第一页| 亚洲福利在线观看| www国产精品视频| 中文字幕在线亚洲| 国产精品久久久亚洲| 91av中文字幕| 懂色aⅴ精品一区二区三区蜜月| 91高清免费在线观看| 久久人人爽人人爽爽久久| 亚洲欧美中文字幕| 日本久久中文字幕| 国产视频精品免费播放| 亚洲午夜未删减在线观看| 亚洲精品wwww| 亚洲free性xxxx护士白浆| 欧美性做爰毛片| 91成人国产在线观看| 国产成人一区二区三区小说| 国产日产欧美精品| 国产剧情日韩欧美| 久久成人综合视频| 亚洲综合大片69999| 亚洲午夜精品久久久久久性色| 日韩精品久久久久久久玫瑰园| 欧美激情中文字幕乱码免费| 亚洲福利视频网站| 亚洲人午夜色婷婷| 亚洲国产成人精品电影| 欧美国产日韩二区| 久久夜色精品国产| 欧美性xxxxx极品| 亚洲成人xxx| 色婷婷综合成人av| 精品中文字幕在线2019| 国产亚洲美女精品久久久| 久久久免费观看视频| 欧美在线www| 另类美女黄大片| 成人精品一区二区三区| 色悠久久久久综合先锋影音下载| 91高清视频在线免费观看| 欧美精品一区二区免费| 国产精品久久av| 在线观看91久久久久久| 在线观看日韩欧美| 欧美性高跟鞋xxxxhd| 欧美一区二区三区精品电影| 91精品视频观看| 久久精品国产亚洲精品2020| 91精品视频观看| 91九色蝌蚪国产| 亚洲天天在线日亚洲洲精| 欧美日韩一二三四五区| 日本精品一区二区三区在线| 欧美一区二区三区免费视| 欧美成人免费全部| 精品亚洲一区二区三区四区五区| 久久久精品免费| 国产视频精品一区二区三区| 国产丝袜一区二区三区| 亚洲另类欧美自拍| 日韩欧美精品网址| 国内精品伊人久久| 欧美国产一区二区三区| 成人在线播放av| 77777少妇光屁股久久一区| 国产色综合天天综合网| 在线观看91久久久久久| 亚洲国产精品久久久久| 亚洲乱亚洲乱妇无码| 性欧美长视频免费观看不卡| 亚洲一区二区久久| 国产欧美亚洲视频| 亚洲国产欧美久久| 午夜精品99久久免费| 国产精品成人v| 国产精品久久久| 日韩欧美在线视频日韩欧美在线视频| 国精产品一区一区三区有限在线| 欧美精品福利视频| 日韩大片免费观看视频播放| 清纯唯美日韩制服另类| 国语自产偷拍精品视频偷| 亚洲综合自拍一区| 91久久综合亚洲鲁鲁五月天| 欧美激情在线一区| 青青青国产精品一区二区| 操日韩av在线电影| 日韩精品欧美国产精品忘忧草| 欧美一性一乱一交一视频| 中文字幕精品在线| 欧美亚洲成人xxx| 欧美一区二三区| 精品无人区乱码1区2区3区在线| 2023亚洲男人天堂| 91chinesevideo永久地址| 成人观看高清在线观看免费| 91精品国产综合久久香蕉| 青青草原成人在线视频| 91精品视频在线| 精品美女久久久久久免费| 亚洲免费av片| 欧美人与物videos| 亚洲精品98久久久久久中文字幕| 亚洲第一级黄色片| 亚洲一区亚洲二区| 不卡伊人av在线播放| 久久久在线观看| 精品人伦一区二区三区蜜桃免费| 欧美成年人视频网站欧美| 国产高清视频一区三区| 欧美日韩国产一区在线| 欧美日韩激情美女| 亚洲一区av在线播放| 国产美女久久精品香蕉69| 久久99久国产精品黄毛片入口| 久久精品99久久香蕉国产色戒| 国产一区二区日韩| 欧美性猛交xxxx偷拍洗澡| 久久999免费视频| 亚洲日韩欧美视频| 日韩高清电影好看的电视剧电影| 中日韩美女免费视频网站在线观看| x99av成人免费| 日韩av网站在线|