Example XML for XMLRPC request

User-Agent Tomcat Web Server 3.1 Beta Sun Solaris 2.6 Host newInstance.com Content-Type text xml Content-length 234 lt xml version 1.0 gt lt methodCall gt lt params gt lt param gt lt param gt lt params gt lt methodCall gt The XML-RPC libraries on the server receive this and decode it, matching it with a handler method if one is available that matches . The requested Java method is then invoked, and the server encodes the result back into XML, as shown in Example 11-11.

Example The SOAP envelope

lt article lt name gt Soapbox lt name gt lt url gt lt url gt lt article gt lt soap Body gt lt soap Envelope gt You can see that an encoding is specified within the envelope, allowing an application to determine using the value of the encodingStyle attribute whether it can read the incoming message situated within the Body element. Be sure to get the SOAP envelope namespace correct, or SOAP servers that receive your message will trigger version mismatch errors, and you won't be able to...

Working with the SAXParser class

Once you have an instance of the SAXParser class, you can do more with it than just passing it a File to parse. Because of the way components in large applications communicate these days, it is not always safe to assume that the creator of an object instance is its user. In other words, one component may create the SAXParser instance, while another component perhaps coded by another developer may need to use that same instance. For this reason, methods are provided to determine the settings of...

Example The DTDHandler interface

public void notationDecl String name, String publicID, public void unparsedEntityDecl String name, String publicId, String systemId, String notationName These two methods do exactly what you would expect. The first reports a notation declaration, including its name, public ID, and system ID. Remember the notation structure in DTDs lt NOTATION jpeg SYSTEM images jpeg gt The second method provides information about an unparsed entity declaration, which looks as follows lt ENTITY stars_logo SYSTEM...

JDOM and Factories

Moving right along, recall the discussion from the last chapter on JDOM and factories. I mentioned that you would never see code like this at least with the current versions in JDOM applications This code does not work JDOMFactory factory new JDOMFactory Element rootElement Document document Well, that remains true. However, I glossed over some pretty important aspects of that discussion, and want to pick it up again here. As I mentioned in Chapter 7, being able to have some form of factories...

Obtaining a Parser

The first step to coding Java that uses XML is locating and obtaining the parser you want to use. I briefly talked about this process in Chapter 1, and listed various XML parsers that could be used. To ensure that your parser works with all the examples in the book, you should verify your parser's compliance with the XML specification. Because of the variety of parsers available and the rapid pace of change within the XML community, all of the details about which parsers have what compliance...

Example The AddItemServlet for Castor

import javax.servlet.ServletException import javax.servlet.http.HttpServlet import import import org.exolab.castor.xml.Marshaller import org.exolab.castor.xml.Unmarshaller Castor generated classes import javaxml2.castor.Catalog import javaxml2.castor.Item import javaxml2.castor.types.LevelType public class AddItemServlet extends HttpServlet private static final String CATALOG_FILE public void doPost HttpServletRequest req, HttpServletResponse res throws ServletException, IOException PrintWriter...