Over 10 Million Study Resources Now at Your Fingertips


Download as :
Rating : ⭐⭐⭐⭐⭐
Price : $10.99
Language:EN
Pages: 2

Some knowledge the oracle dom classes

482

Chapter 18

The simplest way to add an element to the datagram is by using the addResultElement method of the XSQLActionHandlerImpl class. This is what you used in the previous example. It creates an element that has the name of the first second argument and the value of the third argument, and it attaches the element as a child to the node argument. It’s a great convenience method, but it isn’t powerful enough to create complex element trees. There is no way to create attributes or children.

To create elements, you use the DOM APIs. The following example shows you how to create the same output as before, except that this time you have an attribute in the element:

import org.w3c.dom.Node;

public class ComplexHelloActionHandler extends XSQLActionHandlerImpl {

XMLText tNode=(XMLText)doc.createTextNode(“hello!”);

Custom Action Handlers 483

elem.appendChild(tNode);

The code itself is fairly straightforward. The node result, which is passed to the handleAction method, is the parent of the xsql:action element that invokes this action handler. If you want to provide XML back to the datagram, you will need to append it to the result node. To create elements and other node types, you will need to use the appropriate create method of the owner document. You can get a handle to the owner document through the getOwnerDocument() method of the node class.

The next example expands on the following one. This time, you create the same ele-ment as the preceding one and then add a couple of child elements. Since the first ele-ment has an attribute, you will need to create it from scratch. The second one doesn’t have an attribute, so you can use the addResultElement() convenience method.

elem.setAttribute(“attr1”,”val1”);

XMLText tNode=(XMLText)doc.createTextNode(“hello!”);

tNode=(XMLText)doc.createTextNode(“A child”);

child1.appendChild(tNode);

How It Works
Login account
Login Your Account
Add to cart
Add to Cart
Payment
Make payment
Document download
Download File
PageId: ELIBFA4A61
img
Uploaded by :
kKA35VxO
Page 1 Preview
some knowledge the oracle dom classes
Sell Your Old Documents & Earn Wallet Balance