I am going through JAXP DOM trail where there is a DOM Mixed Content model as shown below
<sentence>This is an <bold>important</bold> idea.</sentence>
It's been explained as below
Note - The DOM Node API defines nodeValue(), nodeType(), and nodeName() methods. For the first element node, nodeName() returns sentence, while nodeValue()
returns null. For the first text node, nodeName() returns #text, and nodeValue() returns “This is an ”. The important point is that the value of an element is not the same as its content.
My question is why the getNodeValue()
invoked on Element
node returns null. What is it supposed to have? What is actually a value in Element
node? If i want to set a value to an element node, how can I do that ? Please explain.
The value of an Element node is always null by design. See the Node documentation for a list of expected values.
This ultimately comes from the W3C DOM level 3 design.