background image

The addTextNode Method

<< Ordering Coffee | Retrieving the Order Confirmation >>
<< Ordering Coffee | Retrieving the Order Confirmation >>

The addTextNode Method

childName = new QName(
"phone-number");
SOAPElement phoneNumber = customer.addChildElement(childName);
phoneNumber.addTextNode(orderBean.getCustomer().getPhoneNumber());
childName = new QName(
"email-address");
SOAPElement emailAddress = customer.addChildElement(childName);
emailAddress.addTextNode(orderBean.getCustomer().getEmailAddress());
The address element, added next, has child elements for the street, city, state, and zip code.
This information is extracted from the Address component of OrderBean.
childName = new QName(
"address");
SOAPElement address = order.addChildElement(childName);
childName = new QName(
"street");
SOAPElement street = address.addChildElement(childName);
street.addTextNode(orderBean.getAddress().getStreet());
childName = new QName(
"city");
SOAPElement city = address.addChildElement(childName);
city.addTextNode(orderBean.getAddress().getCity());
childName = new QName(
"state");
SOAPElement state = address.addChildElement(childName);
state.addTextNode(orderBean.getAddress().getState());
childName = new QName(
"zip");
SOAPElement zip = address.addChildElement(childName);
zip.addTextNode(orderBean.getAddress().getZip());
The element line-item has three child elements: coffeeName, pounds, and price. This
information is extracted from the LineItems list contained in OrderBean.
List<LineItemBean> lineItems = orderBean.getLineItems();
Iterator<LineItemBean> i = lineItems.iterator();
while (i.hasNext()) {
LineItemBean lib = i.next();
childName = new QName(
"line-item");
SOAPElement lineItem = order.addChildElement(childName);
childName = new QName(
"coffeeName");
SOAPElement coffeeName = lineItem.addChildElement(childName);
coffeeName.addTextNode(lib.getCoffeeName());
childName = new QName(
"pounds");
SOAPElement pounds = lineItem.addChildElement(childName);
pounds.addTextNode(lib.getPounds().toString());
SAAJ Coffee Supplier Service
The Java EE 5 Tutorial · September 2007
1038