The basic use of XML dom4j

Source: Internet
Author: User

1) Domj4 Overview
DOM4J is also a DOM-based parsing tool. Unofficial.
DOM4J, Dom for Java. I.e log4j logging for Java iphone4s iphone for Steven

2) Use steps
To DOM4J's official find jar bag www.dom4j.org

2.1 Reading an XML file
1) Create Saxreader Object
2) Call the Read method reading the XML file
2.2 Writing out an XML file
1) Create XmlWriter object
2) Call writer method to write Document object    1) read XML file    saxreader reader = new Saxreader ()   Document Doc = Reader.read ("XML file Path");     2) write out XML file     XMLWriter writer = new XMLWriter (New Fileoutputstrea M ("XML file Path"));    Writer.write (docuemnt);     method:    Check:        & nbsp element:       element ("name"): First child element        elements ()  : All child elements, return list& nbsp      elements ("name"): Specify all child elements of the name        elementiterator (): All child elements, return iterators            Properties:       attribute attr = Attribute ("name");   Query Property Object      getname ()   Property name  getvalue () property value        attributevalue (" Name ")   Query property values          text:              GetText ()   This content     change:        property value:  attribute.setvaLue ("new attribute value");        text value:  element.settext ("New content")     :      & nbsp Element: Element.addelement ("name")          Properties: Element.addattribute ("name", "value");      Text:  element.addtext ("text");    Delete:        elements: Element.detach ();  & nbsp     Properties: Atrribute.detach ();  ------------------------------------log level: DebugInfowarnErrorFatal

The basic use of XML dom4j

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.