[
next
] [
prev
] [
prev-tail
] [
tail
] [
up
]
9.7
Customizing Nodes
The
Node
interface introduces the following methods for tailoring nodes through cloning.
Node cloneNode(boolean deep)
--Recursively clone also the subtree, if deep is true.
void setNodeValue(String nodeValue)
void setPrefix(String prefix)
The
Document
interface introduces methods for creating XML nodes.
Element createElement(String tagName)
Element createElementNS(String namespaceURI, String
qualifiedName)
Attr createAttribute(String name)
Attr createAttributeNS(String namespaceURI, String
qualifiedName)
CDATASection createCDATASection(String data)
EntityReference createEntityReference(String name)
ProcessingInstruction createProcessingInstruction(String
target, String data)
Text createTextNode(String data)
Comment createComment(String data)
DocumentFragment createDocumentFragment()
--Creates an empty DocumentFragment object.
The
Element
interface introduces methods for adding and removing attributes.
void setAttribute(String name, String value)
Attr setAttributeNode(Attr newAttr)
Attr setAttributeNodeNS(Attr newAttr)
void setAttributeNS(String namespaceURI, String
qualifiedName, String value)
void removeAttribute(String name)
Attr removeAttributeNode(Attr oldAttr)
void removeAttributeNS(String namespaceURI, String
localName)
The
Attr
interface offers a method for modifying the value of a visited attribute node.
void setValue(String value)
<..
DOM clone
..>
Element
e
=
doc.getDocumentElement();
e.appendChild(
e.cloneNode(true)
);
new
TreeTraverser
(doc);
-_-_-
<?xml
version="1.0"
encoding="UTF-8"?>
<article
xmlns="x:y"
attr="ignored">
<section>
A
&
B
</section>
</article>
#document
article
#text
section
#text
#text
article
#text
section
#text
#text
[
next
] [
prev
] [
prev-tail
] [
front
] [
up
]