1. How XML is parsed using dom
- Based on the DOM (Document Object Model) parsing method, the entire XML file is loaded into the memory and converted into a DOM tree, therefore, applications can randomly access any data in the DOM tree;
- Advantages: high flexibility and fast speed;
- Disadvantage: resource consumption is high;
2. Elements vs nodes (nodes contain elements)
- Nodes include element nodes, attribute nodes, and text nodes.
<! -- Students. xml -->
<? XML version = "1.0" encoding = "UTF-8"?> <Students> <student> <name ID = "001" xx = "Haha"> Michael Zhang </Name> <sex> male </sex> <age> 20 </age> </student> <name ID = "002"> Li Si </Name> <sex> female </sex> <age> 21 </age> </student> </students> // element node: student, name, sex, age // attribute node: ID, AA // text node: James, male, 20
- The element must be a node, but the node is not necessarily an element.
3. XML parsing example using dom
XML-dom parsing XML