JavaLive Transcripts Index
JavaTM API for XML Processing (JAXP)
August 27, 2002
Guest Speakers: Rajiv Mordani and Gopal Sharma
Moderator: Edward Ort (MDR-EdO)
This is a moderated forum.
MDR-EdO: Welcome to JavaTM Live! Today's session is on the Java API for XML Processing (JAXP), a Java API for parsing and processing XML documents. The API is a key part of the Java Web Services Developer Pack and the Java XML Pack. Our guests are two key members of Sun's JAXP engineering team: Spec Lead Rajiv Mordani, and RI Technical Lead Gopal Sharma. They're ready to answer your JAXP questions. So let's begin.
Xman: Can I use JAXP to parse and extract content from a WSDL file? Where can I find a list of JAXP 1.2-compliant parsers?
Rajiv Mordani: There is a list of JAXP 1.2-compliant parsers and XSLT engines here. And yes, you can use JAXP to parse and retrieve content from a WSDL file.
Gopal Sharma: You can find more XML-specific information on Sun's site, or on the Apache site.
brfh: Now that JAXP is integrated into the Web Services Pack, if I want to use only XML parsing, which methods would I use?
Rajiv Mordani: You have a couple of possible ways to get to JAXP. You can download either the Java Web Services Developer Pack or the Java XML Pack; or, if you are already using J2SETM 1.4 or higher, it has JAXP integrated in it.
brfh: Why is Sun still maintaining two versions of the parser? Why can't everyone just use Xerces?
Rajiv Mordani: As of JAXP 1.2, we have moved to Xerces version 2.
bryan: If I have a result object from a transform, what is the best way to validate that object against a dtd?
Gopal Sharma: You can convert to a DOM/Stream/SAX result, and than supply the result to the parser to validate it.
brfh: Are there any plans to implement a simple serializer? Right now, the choice seems to be the org.apache.xerces.serializer. Are there other options?
Rajiv Mordani: Currently, the way you can achieve the equivalent of org.apache.xerces.serializer is to use the Transform API from JAXP. Take a look at the spec to see an example of how to use the transformer as a serializer. DOM Level 3 is going to have support for serialization, too.
Xman: What's the current status of DOM 3, and when will it be supported by JAXP?
Rajiv Mordani: DOM Level 3 is split up into various sub-specs, and most of the specs are still a working draft in w3c. Once they become a recommendation, they will find their way into JAXP in a future version.
brfh: All production JVMs simply won't upgrade to 1.4 immediately. Also, the whole Web Services Developer Pack is too bulky. Do you have comments on this?
Rajiv Mordani: You have a couple of alternatives: You can download the Java XML Pack, which is smaller than the Web Services Pack; or, look at the list of compliant parsers at the URL I mentioned earlier in the chat, and get one of those.
sunil: Will we be able to see a performance increase in XML processing soon?
Gopal Sharma: We are working on this, and you should see improvements soon.
Rajiv Mordani: There is also work going on in the Java Community ProcessSM (JCP) to define a pull parser (JSR 173). That should also help improve parsing performance.
Suresh: Can we create an XML/XSL file dynamically using parsers?
Gopal Sharma: Yes, you can use the serialization package in Xerces.
Eric: If I want to use the DOM to create XML from a legacy data source, what sort of legacy data source could I transform? What is an example of a real-world application?
Rajiv Mordani: I'm not sure if this is what you're looking for, but one example is when a bank wants to exchange information between its departments; it gets the data from the database and then ships it across as XML.
brfh: What is the best way to use the parser in a browser, without having to transfer the bulky parser JAR file to the client? The client may only need partial parser functionality.
Rajiv Mordani: If you move to a 1.4 plug-in in the browser, you shouldn't have to ship the JAR ;). There are probably other, browser-specific ways. If you have the JAR on the client machine, you can bring up the browser in a way that it is in its classpath.
songhzhi: Is there any size limit when parsing an XML document using DOM?
Gopal Sharma: No limit.
brfh: Given the process of importing and exporting nodes from a DOM, is there a better way to transfer nodes across DOM trees?
Rajiv Mordani: There is work going on in J2METM land to develop an API for doing Web services (see JSR 172). As part of the specification, they plan to define a subset of APIs to parse XML documents on J2ME clients. The DOM specification is developed in the w3c. I would recommend sending in your comments to the w3c DOM working group.
Suresh: Parsers accept an XML file as input for parsing, but there is no way to send XML as a string to the parsers, is there?
Gopal Sharma: Please try this: DocumentBuilder.parse(String )/SAXParser.parse(String). You can specify your data as an XML string.
Xman: Are there any plans to open source JAXP?
Gopal Sharma: JAXP is already being developed in open source; there are more details here.
brfh: What is the best way to implement a UI around XML, without going through the JTree complexity? Any plans to expose a DHTML output interface from the parser directly that may support dynamic source update?
Rajiv Mordani: As of now, there are no plans to expose any interfaces for DHTML. A simple way to implement the UI is to define an XML format, and then associate a style sheet to generate, for example, HTML to display in the browser.
Xman: How do I do DOM content validation with JAXP?
Gopal Sharma: Use setValidating(true):DocumentBuilderFactory. It will do the rest.
songhzhi: What are the main differences between SAX and the DOM parser? Which one do you recommend when parsing a large XML document? Certainly, performance is the main concern in such situations.
Gopal Sharma: To learn the exact difference, see the JAXP tutorial. But the short answer is: For parsing large files, SAX is better as far as memory consumption is concerned.
brfh: what is the role of JAXP in Axis?
Rajiv Mordani: All specializations of XML require a parser to parse the content. Axis is an implementation of SOAP in Apache, so it needs a parser to parse the SOAP methods. Now I haven't checked, but my assumption is that they need a JAXP parser ;).
brfh: Any plans to return SOAP fault wrappers natively for errors, such as invalid XML?
Rajiv Mordani: SOAP faults are specific to SOAP. There are APIs for accessing SOAP messages, and doing rpc using SOAP - JAXM and JAX-RPC -- and they return SOAP faults. It doesn't make sense in the case of processing normal XML to return SOAP faults.
Suresh: I have downloaded xalan-j_2_4, and there is a method DocumentBuilder.parse(String), but the string is a URI, not string XML data.
Gopal Sharma: I wasn't clear enough earlier. Please use StringReader(String), and then pass it to StreamSource(Reader).
mikekloster: What guidelines are being used when generating the .java files? For example, let's say a getter method returns a java.util.List of Invoice objects, and I am hand-coding the method. I would declare the method like this: public List getInvoices() in the DTD, and the element would be Invoice (singular), with a * to indicate repetition. The early-access release of JAXB names the method to get the invoices like this: public List getInvoice(); (singular) Was this a purposeful decision?
Rajiv Mordani: I'm not aware of the details on JAXB. You might want to send in your question to Joe Fialli, who is the spec lead for JAXB.
sunil: Will new updates to JAXP be available in the next major SDK release, or can updates be expected earlier?
Rajiv Mordani: As of now, the plan for the next major release of JAXP is to be in the next J2SE release (1.5). However, if there is significant demand to update to newer external standards, we might have a revision earlier than J2SE 1.5.
brfh: Is there a way to parse XML inside a single XML element? Any way the parser will allow such data to go as it is?
Rajiv Mordani: I don't understand what you mean by "parse XML inside a single XML element"? Every document has a root element, with XML within that single element. If that's what you mean...
brfh: Example: <xml1>|<element2><xml2> // Does this need to be parsed or not? Can this be switched? </element2> |
Rajiv Mordani: No, it cannot be switched. However, once the pull parser is available, there may be a way to do things like this. Stay tuned for that.
Xman: Are there any performance implications in using JAXP, or is performance purely related to the parser being used?
Gopal Sharma: JAXP is just an abstract layer. The bare minimum time required in JAXP is to search the Impl. The rest depends on the parser and implementation being used.
Xman: What extensions to JAXP are you considering for the future?
Rajiv Mordani: At a minimum, a move to the newer version of SAX and DOM, and bug fixes in the Transform API. Is there anything specific you are looking for in a newer version of JAXP?
Xman: How about an API to do XPath?
Rajiv Mordani: DOM Level 3 is adding support for XPath. We are also investigating ways to provide more support than just DOM Level 3. If anyone has suggestions for what should be in the API, feel free to send me comments at rajiv.mordani@sun.com.
songhzhi: It shouldn't be too difficult to implement a graphical editor for XML documents, say, using JTree. Are there already such editors on the market, and are there any free ones to try? If yes, I would not bother to do the code myself.
Gopal Sharma: I can't recall the URL, but I know one such UI is available. Please do a Google search or ping me later at gopal.sharma@sun.com.
brfh: Is there any implementation that can take binary data (such as from Excel) and output it as XML? Are there any plans to implement DocumentBuilder.parseMSXL("file") :) :) ?
Rajiv Mordani: There isn't any way to easily take binary data and output it as XML. I do know that MS Office XP does use some kind of XML format to store data, and that can be parsed and transformed using JAXP. And no, there is no plan to add a parseMSXL method to DocumentBuilder.
Rajiv Mordani: A question for the audience: Are the SAX, DOM, and Transform APIs (as part of JAXP) enough for your needs, or are you looking for a more Java-friendly API as part of JAXP? Feel free to send me comments on this.
brfh: Are there any existing APIs for XML-portable Java object transforms, back and forth? Transferring XML over wire is still insecure, except for doing HTTPS. Are there any plans to enhance security by, say, transforming parser output to encrypted output and back without too much code?
Rajiv Mordani: To transform XML to Java objects, you could use JAXB, which should be available soon. Alternatively, you could use the XML encryption or XML digital signatures to sign and encrypt the XML documents. There is an implementation of XML digital signatures at Apache.
Alan: Will XML replace serialization in the near future?
Rajiv Mordani: I don't think one will replace the other. In fact, XML could be used as a serialization format, although that depends on the needs of the application.
Rich: Are the resources on Sun's Web site the best way to learn about JAXP, DOM, and SAX (for instance, their tutorials)? Does some other resource strike you as particularly useful?
Gopal Sharma:Yes, the tutorial on Sun's site is one of the best ways to learn about DOM, SAX, and so on. You can also learn from the W3 tutorials, the w3 site itself, and the official SAX Web site.
brfh: Finally, is there any way I can get an XML transcript of this chat?
Rajiv Mordani: That's an excellent question. We will investigate ways to do this. ;)
MDR-EdO: Well, we've quickly come to the end of our session. I want to thank all of today's participants. I thought we had a very nice set of questions. And, of course, I'd especially like to thank our guests, Rajiv and Gopal, for their answers. Look for a transcript of today's session on the JDC in a day or two.
Rajiv Mordani: Thanks to all the guests on the forum for the questions. If there are any followups, feel free to send me email or send feedback to javaxmlpack-feedback@sun.com or jwsdp-feedback@sun.com.
Gopal Sharma: Thanks, everyone, for your time and questions. Please feel free to ping me.
MDR-EdO: Last moderator (me) signing off. The forum is now unmoderated.

Reader Feedback
Tell us what you think of this transcript.