在dom4j里面这两个方法都返回的是list,但是两个list可能有所不同。看了例子:
xml文件:
<?xml version="1.0"?>
<note>
<to></to>
<from>John</from>
<heading>Reminder</heading>
<body>5555
<head>333</head>
</body>
</note>
java文件:
File file=new File("C:\\Users\\Administrator\\Desktop\\zzz\\1.xml");
SAXReader reader=new SAXReader();
Document document=reader.read(file);
System.out.println(document.getRootElement().elements());//取到该元素下的子节点,对于孙子节点取不到
System.out.println(document.getRootElement().elements().size());//有多少个直接子节点
System.out.println(document.getRootElement().content());//可以取到该元素下所有的后代元素,其中还包括后代元素的text内容
System.out.println(document.getRootElement().content().size());//有多少个后代元素,包括他们text内容的总个数
执行结果:
[org.dom4j.tree.DefaultElement@19fcc69 [Element: <to attributes: []/>], org.dom4j.tree.DefaultElement@253498 [Element: <from attributes: []/>], org.dom4j.tree.DefaultElement@9fef6f [Element: <heading attributes: []/>], org.dom4j.tree.DefaultElement@209f4e [Element: <body attributes: []/>]]
4
----------------------------------------------------------------------------------------------
[org.dom4j.tree.DefaultText@17172ea [Text: "
"], org.dom4j.tree.DefaultElement@19fcc69 [Element: <to attributes: []/>], org.dom4j.tree.DefaultText@12f6684 [Text: "
"], org.dom4j.tree.DefaultElement@253498 [Element: <from attributes: []/>], org.dom4j.tree.DefaultText@f38798 [Text: "
"], org.dom4j.tree.DefaultElement@9fef6f [Element: <heading attributes: []/>], org.dom4j.tree.DefaultText@4b222f [Text: "
"], org.dom4j.tree.DefaultElement@209f4e [Element: <body attributes: []/>], org.dom4j.tree.DefaultText@b169f8 [Text: "
"]]
9
相关推荐
Table of Contents Part 1 Starting with jQuery Chapter 1 Introducing jQuery Part 2 Core jQuery Chapter 2 Selecting elements Chapter 3 Operating on a jQuery collection Chapter 4 Working with properties...
$() looks for DOM elements within the context of the current HTML document. If you do specify a context, such as a DOM element or jQuery object, the expression will be matched against the contents of...
$() looks for DOM elements within the context of the current HTML document. If you do specify a context, such as a DOM element or jQuery object, the expression will be matched against the contents of...
Chapter 4. Events Chapter 5. Making Your Site Snazzy with jQuery Chapter 6. Better Forms with jQuery Chapter 7. Talking to Your Server Chapter 8. Writing Code that You can Read Later Chapter 9. Faster...
本书还包括详细的参考手册,涵盖了JavaScript的核心API、遗留的客户端API和W3C标准DOM API,记述了这些API中的每一个JavaScript对象、方法、性质、构造函数、常量和事件处理程序。 这本最畅销的JavaScript参考书的第...
Chapter 4: Polymer Elements Chapter 5: First Application with Polymer Chapter 6: Polymer Designer Tool and Polymer Starter Kit Chapter 7: Working with Polymer.dart Chapter 8: Best Practices
D3.js 4.x Data Visualization - Third Edition by Andrew Rininsland English | 28 Apr. 2017 | ASIN: B01MG90SSJ | 308 Pages | AZW3 | 6.6 MB Key Features Build interactive and rich graphics and ...
$() looks for DOM elements within the context of the current HTML document. If you do specify a context, such as a DOM element or jQuery object, the expression will be matched against the contents of...
$() looks for DOM elements within the context of the current HTML document. If you do specify a context, such as a DOM element or jQuery object, the expression will be matched against the contents of...
Table of Contents Chapter 1: The Oppressive Magic of jQuery Chapter 2: You Don’t Need jQuery (Anymore) Chapter 3: Understanding the Web API and “Vanilla” JavaScript Chapter 4: Finding HTML Elements...
Chapter 4: Functions And Scope Chapter 5: Javascript-An Object-Based Language Chapter 6: String Manipulation Chapter 7: Date, Time, And Timers Chapter 8: Programming The Browser Chapter 9: Dom ...
Chapter 4: JavaScript Primer 61 Chapter 5: jQuery Basics 93 Chapter 6: Managing the Element Selection 117 Chapter 7: Manipulating the DOM 145 Chapter 8: Manipulating Elements 177 Chapter 9: ...
Chapter 12 Accessing DOM Elements Chapter 13 Creating a Single-Page App Using React Router Chapter 14 Building a Todo List App Chapter 15 Setting Up Your React Development Environment Chapter 16 The...
Part IV is a reference for client-side JavaScript, covering legacy web browser APIs, the standard Level 2 DOM API, and emerging standards such as the XMLHttpRequest object and the <canvas> tag. ...
Part IV is a reference for client-side JavaScript, covering legacy web browser APIs, the standard Level 2 DOM API, and emerging standards such as the XMLHttpRequest object and the <canvas> tag. ...
12 Accessing DOM Elements in React 13 Setting Up Your React Dev Environment 14 Working with External Data in React 15 Building an Awesome Todo List App in React 16 Creating a Sliding Menu in React...
Chapter 52: Application: Outline-Style Table of Contents. Chapter 53: Application: Calculations and Graphics. Chapter 54: Application: Intelligent "Updated" Flags. Chapter 55: Application: Decision...
Chapter 4. Developing a Mobile App with Dart Chapter 5. Web Components and polymer.dart Chapter 6. AngularDart Chapter 7. Server-side Applications with Dart Chapter 8. Testing and Profiling the Dart ...
Python Documentation contents What’s New in Python What’s New In Python 3.6 Summary – Release highlights New Features PEP 498: Formatted string literals PEP 526: Syntax for variable annotations ...
Contents Finishing Your Modules 154 Defining Module-Specific Errors 154 Choosing What to Export 155 Documenting Your Modules 156 Try It Out: Viewing Module Documentation 157 Testing Your Module ...