Name
Text
Synopsis
public interface Text extends Node {
// Public Instance Methods
public abstract boolean isComment( );
}
Text
is a subinterface of Node
that holds the text parts of a SOAP message. A
Text
node can only be created by using the
addTextNode( )
method of
SOAPElement
, as shown in the following code
extract:
SOAPElement element = body.addChildElement("BookTitle"); SOAPElement element2 = element.addTextNode("J2ME in a Nutshell");
This code creates an element called BookTitle
and
adds the given text as its value, resulting in the following XML when
the message is serialized:
<BookTitle>J2ME in a Nutshell</BookTitle>
The value returned by the addTextNode( )
method is
actually a reference to the SOAPElement
beneath
which the Text
node was added. In the code extract
shown previously, therefore, element2
is set to
the same value as element
. The value of the text
associated with a SOAPElement
can be obtained by
calling getValue( )
on the element itself, rather
than by first obtaining a reference to the intervening
Text
object:
// Returns "J2ME in a Nutshell" String text = element.getValue
In fact, there is no direct way to get a reference to the
Text
element itself. The only way to do this is to
use the getChildElements( )
method of the parent
SOAPElement
and search for a child of type
Text
:
Iterator iter = element.getChildElements; while (iter.hasNext() { Node node = (Node)iter.next(); if (node instanceof Text) { // This also prints "J2ME in a Nutshell" System.out.println("Value of ...
Get Java Web Services in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.