dom4j中branch,node,element区别

来源:互联网 发布:男士 护肤品牌 知乎 编辑:程序博客网 时间:2024/05/17 02:19


Branch interface defines the common behaviour for Nodes which can contain child nodes (content) such as XML elements and documents. This interface allows both elements and documents to be treated in a polymorphic manner when changing or navigating child nodes (content).

Element interface defines an XML element. An element can have declared namespaces, attributes, child nodes and textual content.

Some of this interface is optional. Some implementations may be read-only and not support being modified. Some implementations may not support the parent relationship and methods such asNode.getParent()or .

Node defines the polymorphic behavior for all XML nodes in a dom4j tree.

A node can be output as its XML format, can be detached from its position in a document and can have XPath expressions evaluated on itself.

A node may optionally support the parent relationship and may be read only.

若有如下xml:

<?xml version='1.0' encoding='UTF-8'?><GateDocument><TextWithNodes><Node id="0" /><Node id="2" />Amman -- <Node id="11" />Jordan<Node id="17" />,</TextWithNodes></GateDocument>
如果TextWithNodes目前是作为一个element而没有cast的话,此时遍历其子节点会发现只有几个Node而没有文字。

可以将其cast成branch。

0 0