Java operations on XML files and java operations on xml files

Source: Internet
Author: User

Java operations on XML files and java operations on xml files
Zookeeper can be used in four ways: DOM, JDOM, Sax, and Dom4j.

What is the difference between Node and Element in xml?
Node is relative to the data structure like Tree, while Element is the concept in xml.
A node is not necessarily an element, but an element must be a node.
A node that must contain complete information is an element.
Element is inherited from Node, and Element can have attributes and subnodes.
Add
AppendElement ()
CreateElement ()
Modify
SetAttribute ()
SetTextContent ()
Delete
GetParentNode (). removeChild ()
Save
TransformerFactory
DOMSource: act as the holder of the conversion Source tree in the form of the Document Object Model tree
StreamResult: the owner of the Conversion Result. It can be a tag in XML, plain text, HTML, or some other formats.
Search
XPathFactory:
XPath: provides access to the XPath computing environment and expressions.
XPath. evaluate ()

How to use java to operate xml files

Dom4j is a good thing and is easy to use.
Here is a very detailed introduction. ibm's article describes in detail the steps for creating and modifying xml.

Www.ibm.com/..j.html

Operate XML files in java

Public void testWrite (){

// Create related nodes
Element root = new Element ("person ");

Element name = new Element ("name ");
Name. addContent ("James ");
Element age = new Element ("age ");
Age. addContent ("24 ");
// Add the child node to the parent node
Root. addContent (name );
Root. addContent (age );
// Create a document Object
Document doc = new Document (root );
// Output the created xml file
XMLOutputter out = new XMLOutputter ();
Try {
Out. output (doc, new FileOutputStream ("c:/person. xml "));
} Catch (FileNotFoundException e ){
// TODO Auto-generated catch block
E. printStackTrace ();
} Catch (IOException e ){
// TODO Auto-generated catch block
E. printStackTrace ();
}

}
 

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.