What is a node:
Data structure of nodes relative to trees. A tree is made up of nodes. This part can refer to the tree diagram of discrete mathematics.
What is an element?
Element is a concept in XML,
The difference between an element and a node is that an element is a small definition, for example, only a node with complete information is an element.
& lta & gt
& ltb & gt& lt/b & gt;
& ltb & gt& lt/b & gt;
& lta & gt
DOM treats everything in the file as a node >: element.
1DOM generates a tree according to the structure of the whole file when parsing the file, and stores it all in memory.
The advantage is that the whole file is always in memory, we can visit any node at any time, and we are familiar with the operation of traversing the tree; The disadvantage is that it consumes memory and cannot be processed until all documents have been read into memory.
It should be noted that the space between two tags of an XML file is also a node (text node) of this tree. & lta & gt& ltb & gt& lt/b & gt; & lta>a has three nodes.
element root = doc . getdocumentelement(); : what is root?
NodeList list = root . get child nodes(); I don't know if root is a node or an element.
There are several subtypes of nodes:
Elements,
Words,
Attribute,
Root element,
Comments,
Namespace, etc
An element is a node that can have attributes and child nodes.
Element is inherited from the node.
change
If (node.getNodeType() == element. Element _ node)
{
Element e = (element) node;
}
? Does Elemental have children?
Elements and attributes
1 e.getAttributes()
2 e.getChildNodes()
3 e.getTagName()
element root = doc . getdocumentelement(); : what is root?
NodeList list = root . get child nodes(); I don't know if root is a node or an element.
The public void domParse (string file name) threw an exception {
DocumentBuilderFactory f = DocumentBuilderFactory . new instance();
document builder db = f . newdocumentbuilder(); constructor
Documentdocument = db.parse (new file (file name)); Paris
element El = document . getdocumentelement(); root
Domred (El);
}
public void DOM read(Element current node){
if ("struts-config "。 equals(current node . get nodename()){
config = new struts config();
}
NodeList list = current node . get child nodes();
for(int I = 0; I< list. getlength (); i++) {
node node = list . item(I);
If (node.getNodeType() == element. Element _ Node) {
Element e = (element) node;
if ("form-beans "。 equals(e . gettagname()){
formBeans = new ArrayList & ltFormBeanConfig & gt();
Domred (e);
}
if ("form-bean "。 equals(e . gettagname()){
formbean config fc = new formbean config();
NamedNodeMap attrs = e . get attributes();
for(int j = 0; j & ltattrs . getlength(); j++) {
Attr Attr =(Attr)attrs . item(j);
If ("name". equals(attr . getname()){
fc . setname(attr . getvalue());
} Otherwise {
fc . settype(attr . getvalue());
}
}
form beans . add(fc);
}
If ("action mapping". equals(e . gettagname()){
actions = new ArrayList & ltActionConfig & gt();
Domred (e);
}
If ("action". equals(e . gettagname()){
action config AC = new action config();
NamedNodeMap attrs = e . get attributes();
for(int k = 0; k & ltattrs . getlength(); k++) {
Attr Attr =(Attr)attrs . item(k);
If ("path". equals(attr . getname()){
AC . set path(attr . getvalue());
} else if ("type "。 equals(attr . getname()){
AC . settype(attr . getvalue());
} Otherwise {
AC . set name(attr . getvalue());
}
}
actions . add(AC);
}
}
}
}
The difference between nodes and elements in xml node objects is the main data type of the whole DOM. The node object represents a single node in the document tree. Nodes can be element nodes, attribute nodes and text nodes.
The Element object represents an element in an XML document. Elements can contain attributes, other elements or text.
In the XML tree structure, only the attributes and characters of nodes and elements are nodes.
The differences between elements, nodes and Attr in XML and between elements and nodes are 1. An element is a very small definition, and it must be a node with complete information to become an element, such as
What is a node:
Data structure of nodes relative to trees. A tree is made up of nodes. This part can refer to the tree diagram of discrete mathematics.
What is an element?
Element is a concept in XML,
The difference between an element and a node is that an element is a small definition, for example, only a node with complete information is an element.
& lta & gt
& ltb & gt& lt/b & gt;
& ltb & gt& lt/b & gt;
& lta & gt
DOM treats everything in the file as a node >: element.
1DOM generates a tree according to the structure of the whole file when parsing the file, and stores it all in memory.
The advantage is that the whole file is always in memory, we can visit any node at any time, and we are familiar with the operation of traversing the tree; The disadvantage is that it consumes memory and cannot be processed until all documents have been read into memory.
It should be noted that the space between two tags of an XML file is also a node (text node) of this tree. & lta & gt& ltb & gt& lt/b & gt; & lta>a has three nodes.
element root = doc . getdocumentelement(); : what is root?
NodeList list = root . get child nodes(); I don't know if root is a node or an element.
There are several subtypes of nodes:
Elements,
Words,
Attribute,
Root element,
Comments,
Namespace, etc
An element is a node that can have attributes and child nodes.
Element is inherited from the node.
change
If (node.getNodeType() == element. Element _ node)
{
Element e = (element) node;
}
? Does Elemental have children?
Elements and attributes
1 e.getAttributes()
2 e.getChildNodes()
3 e.getTagName()
Excuse me, in xml, the difference between document nodes and document elements refers to nodes first, followed by elements in nodes.
such as
& lt book type = c> book
The difference between Node and Element Node objects is the main data type of the whole DOM. The node object represents a single node in the document tree. Nodes can be element nodes, attribute nodes and text nodes. The Element object represents an element in an XML document. Elements can contain attributes, other elements or text.
Dom4j simply learned the difference between elements and nodes, so we can understand nodes and elements in this way. A node is a node, an attribute, a piece of text, a comment, etc. They are all nodes, and element is an element, which is a relatively complete xml element, that is, the xml "node" we verbally say (the word "knot" is specially used here to express the difference from "node" nodes), hehe. ...
Dom4j help files are in dom4j-1.6.1/docs/guide. They are all in English, but they should be basically understandable.
1, four ways to manipulate xml: SAX, DOM, JDOM, DOM4J.
2.DOM (Document Object Model): It means to put the whole xml as a whole object directly into memory, no matter how big the xml file is;
3.SAX=Sample API for xml: If the xml file has 2G, it is very difficult to use the first method. SAX uses a similar streaming media method.
DOM and SAX are both java APIs, and it is relatively difficult to process xml files, so the following two frameworks appear and wrap the above two frameworks.
4、JDOM:
5、DOM4J:
6. Parse xml file with DOM4J (read all attribute nodes).
A document can be understood as an entire document object.
Take the root node. Document.getRootElement () returns an element.
7. Understand the usage of xpath. path is the path, and xpath looks for a specific node in an xml file.
Document.selectnodes ("hibernate-mapping/class/property"), where hibernate-mapping is the root node. Change the returned by dom4j. Node object.
Documents. Selectsinglenodes ("hibernate-mapping/class/property") only takes the first one.
In base, @name is property, and property name valueOf is the value of name;
Jaxen package needs to be added in DOM4J.
8. Generate the xml file of DOM4J.
9. When generating an xml file with FileWriter, there may be no format, so you can use XMLWriter class to beautify it automatically.
10 and DOM4J modify the xml file; Rarely used.
1 1.freemarker or velocity is often used to automatically generate code, which is commonly used. Dom4j generation is also rarely used.
12. How to generate an xml file with the structure in the table?
13、JavaDB
A) Properties object: it can be understood as a table corresponding to keys and values.
14, Databasemetadata, you can read the table structure of the database through this JDK class and do your own thing through this table structure. (Familiar with usage) Learn through JDK files and Google.
15. Metadata is data, which is used to describe data.
16, DWR, Ajax framework is well sealed, which is a combination of class and java.
This file consists of nodes. For example, an element node is a node node. There are also text nodes and attribute nodes. I hope to adopt. P is an element node, title="tips "is an attribute node, and Chinese characters are text nodes.